javascript href attribute


  Translation results:

abbr.horizontal reference horizontal reference, horizontal datum

javascript href attributesyntax

Function: Set or return the URL of the linked resource.

Syntax: anchorObject.href=URL

javascript href attributeexample

<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript">
        function changeLink()
        {
            document.getElementById('myAnchor').innerHTML="访问 phpStudy"
            document.getElementById('myAnchor').href="http://www.phpStudy.net"
            document.getElementById('myAnchor').target="_blank"
        }
    </script>
</head>

<body>
<a id="myAnchor" href="http://www.php.cn">访问 php中文网</a>
<input type="button" onclick="changeLink()" value="改变链接">
<p>在本例中,我们改变超链接的文本和 URL。我们也改变 target 属性。target 属性的默认设置是 "_self",这意味着会在相同的窗口中打开链接。通过把 target 属性设置为 "_blank",链接将在新窗口中打开。</p>
</body>

</html>

Run instance »

Click the "Run instance" button to view the online instance

Home

Videos

Q&A