0

我的代码:

<div id="box">
<p>
    123
</p>
<p>
    abc
</p>
</div>

<script>
     var html = document.getElementById("box").innerHTML;

     alert(html)  //you can the different HTMLString between IE6/7/8 and IE9/FF 

     for (var i = 0, len = html.length; i < len; i++) {
         var word = html.charAt(i)
         if(i == 0){
           alert(word=="\n")  // IE6/7/8: false .     IE9/FF:true     
         }
         if(i == 11){
           alert(word=="\n")  //Look at here in IE6/7/8, why is false ??????
         }
     }
</script>

当 (i==11) 时,IE6/7/8 中此处的字符正在换行,但为什么显示为 false?

怎么写我可以知道html的代码在IE6/7/8中换了一个新行??

4

1 回答 1

0

你可以用有条件的评论来做到这一点,比如

<!--[if IE 6]>
<script>
     var html6 = document.getElementById("box").innerHTML;

     alert(html6)  //you can the different HTMLString between IE6/7/8 and IE9/FF 
     }
</script>
<![endif]-->

然后重复 7 和 8。我不是 100% 确定警报会起作用,但你明白了。

于 2013-01-23T05:04:17.067 回答