有关innerHTML的知识

object.innerHTML: object所包含的元素的HTML,不包含object
object.outerHTML: object及它所包含元素的HTML,包含object

<a href="#" onclick="alert(this.innerHTML)">this is innerHTML</a><br>
<a href="#" onclick="alert(this.outerHTML)">this is outerHTML</a><br>

来个应用的
<a href="#" onclick="this.innerHTML='<p onclick=alert(this.outerHTML)>this is outerHTML</p>' ">this is innerHTML</a>
上面都是采用的this本身,下面采用id对应object
<button onclick=alert(obj1.innerHTML)>obj1.innerHTML</button>

<button onclick=alert(obj2.outerHTML)>obj2.outerHTML</button>

<div id=obj1><font color=blue>cnbruce</font></div>

<div id=obj2><font color=red>cnrose</font></div>

innerText

<SELECT NAME="cn_who">
<option value="male">cnbruce</option>
<option value="female">cnrose</option>
</SELECT>

<INPUT TYPE="button" VALUE="The Node" onClick="alert(cn_who.children[0].nodeName)">
<INPUT TYPE="button" VALUE="The Name" onClick="alert(cn_who.children[0].innerText)">
<INPUT TYPE="button" VALUE="The Sex" onClick="alert(cn_who.children[0].value)">
<INPUT TYPE="button" VALUE="The Node" onClick="alert(cn_who.children[1].nodeName)">
<INPUT TYPE="button" VALUE="The Name" onClick="alert(cn_who.children[1].innerText)">
<INPUT TYPE="button" VALUE="The Sex" onClick="alert(cn_who.children[1].value)">

insertAdjacentText
 
<a href="#" onclick="this.insertAdjacentText('afterEnd',' cnbruce ')">insertAdjacentText</a>

posted @ 2008-05-16 14:40  Athrun  阅读(484)  评论(0编辑  收藏  举报