关于js字符串转成函数

STPace 2016-04-27

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>

<p id="demo">My First Paragraph.</p>

<script>
var jsText = 'function(s){alert(s);return s+1;}'

var jscode = new Function('return '+jsText)();

var a=jscode(2);
alert(a+1);
</script>

</body>
</html>

相关推荐