http://www.quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
IE applies HTML normalization to the data that is assigned to the innerHTML property. This causes incorrect display of whitespace in elements that ought to preserve formatting, such as <pre> and <textarea>
Test page. Workaround is not included.
I've found out that setting outerHTML doesn't trigger normalization. So I've decided to test for .outerHTML property and if not false (i.e., IE), prepend and append the opening and closing pre tags to the content I want to set and assign that to outerHTML.
// Workaround for IE <PRE> innerHTML normalization quirk
if (elem.tagName == "PRE" && "outerHTML" in elem)
{
elem.outerHTML = "<PRE>" + str + "</PRE>";
}
else
{
elem.innerHTML = str;
}
(Works with IE & FF)
分享到:
相关推荐
innerHTML的使用document.getElementById("id").innerHTML = "contenttext";
innerHTML的简单应用
博文链接:https://aideqianfang.iteye.com/blog/246585
解决ajax返回innerHTML中javascript不能运行问题
js中innerHTML与innerText的用法与区别
超全面javaweb第4天-_08_innerHTML属性
NULL 博文链接:https://wuzhengxuan.iteye.com/blog/1263906
js中innerHTML与innerText的用法与区别js中innerHTML与innerText的用法与区别
innerHTML-outerHTML-innerTEXT
千锋Web前端教程_48_日期对象_定时器和innerhtml
简单日历和innerHTML使用 javascript的简单应用实例 可以自定义Css
Innerself – 使用innerHTML将React / Redux转换成50行代码
innerHtml用法innerHtml用法innerHtml用法innerHtml用法
html js innerHTML outerHTML innerText outerText 等的区别及实例汇总
v-html:更新元素的 innerHTML const text = `<p>Hello World</>` My name is Pjee <p v-html='text'> 注意:你的站点上动态渲染的任意 HTML 可能会非常危险,因为它很容易导致 XSS 攻击。请只对可信内容...
HTML标签的innerHTML和value之间的用法的区别
上例中的test[removed]的值也就是“<span xss=removed>test1</span> test2 ”。... test.outerHTML: 除了包含innerHTML的全部内容外, 还包含对象标签本身。 上例中的text.outerHTML的值也就是<div i
改变文字innerHTML每个HTML元素具有InnerHtml属性定义的HTML代码和文字之间发生的元素的开幕式和闭幕式标记。通过改变一个元素的innerHTML后,一些用户交互,您可以更互动网页。...script type=”text/javascript
调用innerHTML之后,onclick失效了,这也是在意料之中的,因为innerHTML是以文本形式插入的button,所以无法识别onclick事件
相关文章:innerHTML HTML DOM insertRow() 方法Definition and Usage定义与用法The insertRow() method is used to insert a new row in a specified position in a table.insertRow()方法可用来往表格中的指定位置...