前幾天在做網(wǎng)頁(yè)的時(shí)候用到了如何取得和輸出鼠標(biāo)點(diǎn)擊的超鏈接的字符串,在網(wǎng)上搜索用innerText可以取得,于是就找了一下innerText和innerHTML的區(qū)別,下面貼出一個(gè)在網(wǎng)上找到的代碼來(lái)說(shuō)明一下:
輸出字符串
<html>
<head><title>test</title>
<script language="javascript">
function show1(){
document.all.test.innerText="<font color=blue>test</font>";
}
function show2(){
document.all.test.innerHTML="<font color=blue>test</font>";
}
</script>
</head>
<body>
<table><tr><td id=test><font color=red>innerText</font></td>
</tr></table>
<a href="javascript:show1();">testinnerText</a>
<a href="javascript:show2();">testinnerHTML</a>
</body>
</html>
對(duì)于innerText,即把"<font color=blue>test</font>"當(dāng)成整體內(nèi)容顯示出來(lái)。而對(duì)于innerHTML而言,則把"<font color=blue>test</font>"當(dāng)成頁(yè)面的一部分,即顯示蘭色的test字符!