Dom--Anchor Object

本文通过JavaScript演示如何改变HTML页面中链接的文本、URL及目标窗口属性。初始链接指向Microsoft,通过按钮点击事件更改链接至W3Schools,并设置新窗口打开。同时介绍了如何获取链接焦点及设置快捷键。
<html>
<head>

<style type="text/css">
a:active 
{color:green}
</style>


<script type="text/javascript">
function changeLink()
{
document.getElementById('myAnchor').innerHTML
="Visit W3Schools"
document.getElementById('myAnchor').href
="http://www.w3schools.com"
document.getElementById('myAnchor').target
="_blank"
}

function getfocus()
{document.getElementById('myAnchor').focus()}

function losefocus()
{document.getElementById('myAnchor').blur()}

function access()
{
document.getElementById('myAnchor').accessKey
="a"
}


</script>
</head>

<body onload="access()">
<id="myAnchor" href="http://www.microsoft.com">Visit Microsoft</a>
<br /><br />
<input type="button" onclick="changeLink()" value="Change link">
<p>In this example we change the text and the URL of a hyperlink. We also change the target attribute.
The target attribute is by default set to "_self", which means that the link will open in the same window.
By setting the target attribute to "_blank", the link will open in a new window.
</p>
--------------------------------------------------------
<br /><br/>
<input type="button" onclick="getfocus()" value="Get focus">
<input type="button" onclick="losefocus()" value="Lose focus">

<br/>
--------------------------------------------------------
<br /><br/>

<p>(Use Alt + a to give focus to the link.)</p>

</body>

</html>

转载于:https://www.cnblogs.com/Elong/archive/2006/07/14/450971.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值