在IE中 innerText 跟 inner HTML 两个方法都能正常运行
但是FF里面的innerText不可用,但是有一个替代方法: textContent
IE: oDiv.innerText = aString; oDiv.innerHTML = aString;
FF: oDiv.textContent = aString; oDiv.innerHTML = aString;
正则:
<script>
var regExp = /<\/?[^>]+>/gi;//匹配元素的尖角号</script>
function ReplaceTags(xStr) {
console.log(xStr);
xStr = xStr.replace(regExp, "0");
console.log(xStr);
return xStr;
}
var xContent = document.getElementById("test").innerHTML;
var fixedContent = ReplaceTags(xContent);
alert(fixedContent);
</script>
<body>
<div id="test"><span>hello</span><span>world!</span></div>
</body>