JS 链接节点的问题

HTML内联元素innerText与href同步问题

<!DOCTYPE html PUBLIC "-//W3C//DTD xhtml 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> </head> <body> <div id="Container" > <table > <tbody id="tb"> </tbody> </table> <div id="clone"> <img class="PageImg" /> <br /> <a href="empty" mce_href="empty" class="PageHref">empty</a> </div> </div> <mce:script language="javascript"><!-- var strSectionNames = ["www.yahoo.com","www.google.com","news.tom.com"] var nLen = arrSections.length; var oTB = document.getElementById("tb"); var oTR = null; var oTD = null; var oClone = document.getElementById("clone"); var oContent = null; var oPageImage = null; var oPageHref = null; nLen = 6; for( var i=1; i<=nLen; i++ )//去除第一个空字符串 { if( (i-1)%3 == 0 ) { oTR = null; oTB.appendChild( oTR = document.createElement("tr") ); } oTD = null; oTR.appendChild( oTD = document.createElement("td") ); oContent = null; oContent = oClone.cloneNode(true); oContent.style.display = "block"; oPageImage = null; oPageHref = null; oPageImage = oContent.getElementsByTagName("img")[0]; oPageHref = oContent.getElementsByTagName("a")[0]; //关注这里: oPageHref.innerText = arrSections[i]; oPageHref.href = "http://www.163.com"; oTD.appendChild( oContent ); oPageHref = oPageImage = oContent = null; } arrSections = null; strSectionNames = null; nLen = null; oTR = null; oTD = null; // --></mce:script> </body> </html> 

 

这其中对一个链接点的操作:

 

oA.innerText = "www.my.com";

oA.href = "www.other.com";

 

然后结果 oA.innerText 自动变为 www.other.com

如果 oA.href 不是 www开头, 或者 oA.innerText不是 www开头, 就不会有这种情况.

 

oA.href = "www.other.com";

oA.innerText = "www.my.com";

就没有问题了.

 

很奇怪!

转载于:https://www.cnblogs.com/norsd/archive/2009/01/22/6359534.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值