作者s25g5d4 (死城盗贼)
看板Ajax
标题Re: [问题] 有办法完全不用innerHTML吗?
时间Tue Jul 6 20:35:44 2010
<div id="div1">
今天天气真好!
</div>
<script>
var o=document.getElementById('div1');
var ot=document.createElement('b');
ot.appendChild(document.createTextNode('天气'));
o.replaceChild(ot,o.childNodes[0]);
o.insertBefore(document.createTextNode('今天'),ot);
o.appendChild(document.createTextNode('真好!'));
</script>
这样用不会比较好 但是几乎把每个方法都玩到了@@
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.172.103.119
1F:→ s25g5d4:顺便说明一下 用innerHTML弄出来的都会被解译为HTML格式 07/06 20:40
2F:→ s25g5d4:用creatTextNode则会被视为纯文字 所以上面的ot.appendChi 07/06 20:40
3F:→ s25g5d4:ld(document.createTextNode('天气'));改成<i>天气</i>时 07/06 20:41
4F:→ s25g5d4:就会变 今天<i>天气</i>真好! 07/06 20:42