52,797
社区成员
发帖
与我相关
我的任务
分享
<html>
<head></head>
<body>
<script>
function getFunction()
{
var str="abcdefg<script>function Test(){alert('hello');};Test();</"+"script>hijklmn";
var reg=/<script[^>]*>(.+)<\/script>/i;
var ms=str.match(reg);
var s;
if(ms!=null)
s=ms[1];
var st=document.createElement("script");
st.type="text/javascript";
st.text=s;
document.body.appendChild(st);
}
</script>
<input type="button" onclick="getFunction()" value="获取函数"/>
<input type="button" onclick="Test()" value="执行函数"/>
</body>
</html>