日期:2014-05-17  浏览次数:20618 次

让innerHTML的脚本也可以运行起来

var fillHTML = function (el,HTMLString) { 
if (!el) return; 
if (window.ActiveXObject) { //For IE 
el.innerHTML = "<img style='display:none'/>" + HTMLString.replace(/<script([^>]*)>/ig, '<script$1 defer>'); 
el.removeChild(el.firstChild) 
} else { //For Mozilla,Opare 
var nSibling = el.nextSibling; 
var pNode = el.parentNode; 
pNode.removeChild(el); 
el.innerHTML = HTMLString; 
pNode.insertBefore(el,nSibling) 
} 
} 
详细出处参考:http://www.jb51.net/article/236.htm