写了一个简单的函数..作用是解决innerHTML时JS不生效..基于网上某个类修改...
兼容ie6+..Firefox..其它未测!
function set_innerHTML(el, htmlCode) {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
htmlCode = htmlCode.replace(/<script([^>]*)>/gi,'<script$1 defer>');
el.innerHTML = htmlCode;
el.removeChild(el.firstChild);
} else {
var html = htmlCode.replace( /<script[^>]*>([\s\S]*?)<\/script>/mgi, "" );
var code = htmlCode.replace( /[\s\S]*?<script[^>]*>([\s\S]*?)<\/script>[\s\S]*?/mgi, "$1" );
//.和[\s\S] 不一样
el.innerHTML = html;
var wc = T$('wc1217');
if(wc)
wc.parentNode.removeChild(wc);
script = document.createElement("script");
script.defer = true;
script.type = "text/javascript";
script.id = "wc1217";
script.text = code;
setTimeout(function(){document.getElementsByTagName('body').item(0).appendChild( script )},1000);
}
}
//T$就是document.getElementByid