前面长长的***********成你的标志了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
/*
replace函数有两种方式,其中一种,就是第一个参数是要替换的正则式,第二个是用来处理如何替换的函数,replace会调用这个函数
而参数就是前面正则式匹配到的所有字符串,调用函数后的返回值作为替换后的新值
*/
'alert("hello")'.replace(/.+/, eval);//就相当于eval(alert("hello"))
'alert("hello")'.replace(/.+/, function(m){new Function(m)();});//相当于构造一个匿名函数(function(){alert("hello")})()var i = 0; eval(Array(10).join('alert(++i);'));
/*
相当于
eval('alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);')
*/
var i = 0; new Function(Array(10).join('alert(++i);'))();
/*
和上面差不多,不过是用Function实现的
相当于
(function(){
alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);
})()
*/
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
/*
replace函数有两种方式,其中一种,就是第一个参数是要替换的正则式,第二个是用来处理如何替换的函数,replace会调用这个函数
而参数就是前面正则式匹配到的所有字符串,调用函数后的返回值作为替换后的新值
*/
'alert("hello")'.replace(/.+/, eval);//就相当于eval(alert("hello"))
'alert("hello")'.replace(/.+/, function(m){new Function(m)();});//相当于构造一个匿名函数(function(){alert("hello")})()var i = 0; eval(Array(10).join('alert(++i);'));
/*
相当于
eval('alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);')
*/
var i = 0; new Function(Array(10).join('alert(++i);'))();
/*
和上面差不多,不过是用Function实现的
相当于
(function(){
alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);alert(++i);
})()
*/
</script>
</body>
</html>
解决方案 »
- 请教state与status的区别
- 这段JS代码在html里运行不起来!求教!
- js 无法访问
- 麻烦大家,为什么这段JS不支持火狐。
- 对一个文本框输入数值,然后点击按钮,使表单内指定的几个文本框内容变成这个数值
- firefox不支持window.location.href='http://163.com';吗? 有什么等价的方法吗?
- 怎样用javascript判断输入的用户名只能是英文和数字的结合?
- 怎样在页面加载时,让Web页面的效果同“F11”键一样
- 我想在脚本中执行一个shell 命令该怎么做
- 我貌似犯了一个新手常见的错误..但不知怎么改和错误原因,请指教...
- 下面这个插入sql语句是正确的吗?
- JavaScript获取HTML源码截取指定变量值并输出
如
var str = "var a = 123;";
alert(a);//将出错显示a未定义如果在alert前加
eval(str);
则会打印“123”
还是看个例子
var f = new Function("x", "y", "return x * y;");
就与下个函数等价
function f(x, y){return x * y;}