读书人

用正则表达式分开脚本和其他内容

发布时间: 2012-09-15 19:09:28 作者: rapoo

用正则表达式分离脚本和其他内容

//用正则表达式分离脚本和其他内容function   addfriend(url) { $("loading").style.display="block"; var   http=new   ajax(); http.onreadystatechange=function   () { if(ajax_returnresponse(http)) { var resTexthttp.responseText;var reg = /<script[^>]*>((.|\n)+)<\/script>/i;var match=resText.match(reg);var MyScript="";if(match!=null) //有脚本返回{ MyScript=match[1]; eval(MyScript);//执行脚本}var Html=resText.replace(reg,"");//获取不包含脚本的其他内容$("loading").innerHTML=Html; info(); return   false; } } 

读书人网 >编程

热点推荐