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

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

来个应用的

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

上面都是采用的this本身,下面采用id对应object

  1. <button onclick=alert(obj1.innerHTML)>obj1.innerHTML</button>
  2. <button onclick=alert(obj2.outerHTML)>obj2.outerHTML</button>
  3. <div id=obj1><font color=blue>cnbruce</font></div>
  4. <div id=obj2><font color=red>cnrose</font></div>
  5.  
  6. <select NAME="cn_who">
  7. <option value="male">cnbruce</option>
  8. <option value="female">cnrose</option>
  9. </select>
  10.  
  11. <input TYPE="button" VALUE="The Node" onClick="alert(cn_who.children[0].nodeName)">
  12. <input TYPE="button" VALUE="The Name" onClick="alert(cn_who.children[0].innerText)">
  13. <input TYPE="button" VALUE="The Sex" onClick="alert(cn_who.children[0].value)">
  14. <input TYPE="button" VALUE="The Node" onClick="alert(cn_who.children[1].nodeName)">
  15. <input TYPE="button" VALUE="The Name" onClick="alert(cn_who.children[1].innerText)">
  16. <input TYPE="button" VALUE="The Sex" onClick="alert(cn_who.children[1].value)">
  17.  
  18. <a href="#" onclick="this.insertAdjacentText('afterEnd',' cnbruce ')">insertAdjacentText</a>

无觅相关文章插件,快速提升流量