日期:2014-05-16  浏览次数:20387 次

请教DOM一个小问题
<script>
function   embolden(node){
      var   bold=document.createElement( "b ");
      var   parent=node.parentNode;
      parent.replaceChild(bold,node);
      bold.appendChild(node);
}
</script>


<p   id= "p1 "> this   <i> is </i>   paragraph   #1. </p>
<p   id= "p2 "> this   <i> is </i>   paragraph   #2. </p>
<button   onclick= "embolden(document.getElementById( 'p1 ')); "> embolden </button>


按照上面的事件处理程序来说.并不是只将<P>和</P>这两个标记替换成<B>和</B>,而是将 <p   id= "p1 "> this   <i> is </i>   paragraph   #1. </p> 替换成<B>和</B>.我想问下document.getElementById( 'p1 ')得到的元素只是<P>和</P>还是包含this   <i> is </i>   paragraph   #1.?谢谢

------解决方案--------------------
包含this <i> is </i> paragraph #1.
------解决方案--------------------
alert(node.innerHTML);

将显示: this <i> is </i> paragraph #1.