我的代码:
<div id="box">
<p>
123
</p>
<p>
abc
</p>
</div>
<script>
var html = document.getElementById("box").innerHTML;
for (var i = 0, len = html.length; i < len; i++) {
var word = html.charAt(i)
alert("_" + word + "_" + i) //Attention!! when the "i" == 0
if (i == 0) {
alert(word==" ") // it is false.....
}
}
</script>
使用API:“chatAt”,如何编写我可以知道HTML的代码正在改变新的行.....(word == what ????)
答案 0 :(得分:2)
你在寻找吗?
var html = document.getElementById("box").innerHTML;
for (var i = 0, len = html.length; i < len; i++) {
if (html[i] === "\n") {
// new line
}
}