前幾天在做網頁的時候用到了如何取得和輸出鼠標點擊的超鏈接的字符串,在網上搜索用innerText可以取得,于是就找了一下innerText和innerHTML的區別,下面貼出一個在網上找到的代碼來說明一下:
輸出字符串
<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>
對于innerText,即把"<font color=blue>test</font>"當成整體內容顯示出來。而對于innerHTML而言,則把"<font color=blue>test</font>"當成頁面的一部分,即顯示蘭色的test字符!