且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将HTML字符串附加到DOM

更新时间:2022-05-07 05:13:23

如果可用,请使用insertAdjacentHTML,否则使用某种回退。根据 https://developer.mozilla.org/en/DOM/element.insertAdjacentHTML

Use insertAdjacentHTML if it's available, otherwise use some sort of fallback. insertAdjacentHTML will be supported in Firefox 8, and is also supported in Safari 4, Chrome, IE and Opera, according to https://developer.mozilla.org/en/DOM/element.insertAdjacentHTML

div.insertAdjacentHTML( 'beforeend', str );

现场演示: http://jsfiddle.net/euQ5n/