有关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>
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。