JS如何获取A标签里面的链接属性

时间:2022-12-09 09:14:41

<script type="text/javascript">
function dd(){
//document.getElementById ('zhang').getElementsByTagName ("a").href = "http://www.easyboor.com"
//document.getElementsByTagName("a").href="http://www.w3school.com.cn";
var cc = document.getElementById ('myAnchor').innerHTML
var aa = document.getElementById ('myAnchor').getElementsByTagName('a');
alert (aa[0].innerHTML);
aa[0].innerHTML= "易搏";
aa[0].href= "http://www.easyboor.com";
var aa = document.getElementsByTagName('a');
alert (aa[0].href);
}
</script>
<div id="myAnchor" onclick="dd()"><a href="http://www.easyboor.com" >易搏</a></div>

getElementsByTagName('标签') 获取的是一组A标签的数组所有要用过AA[0]来表示第一个。