日期:2014-05-16  浏览次数:20361 次

求高手帮忙改正这段代码,让他生效。
<script type="text/javascript">

alert(1,function(){alert(2);});

var string = "267";
var number = /(\d)\d)\d)/g;
alert(string.match(number),function(a,b,c,d){return document.write(b);});
alert(string.match(number),function(a,$1,$2,$3){return document.write($1);});
</script>


①让alert弹出1的时候运行内部函数弹出2

②让document.write(b)和document.write($1)生效

使用参数abcd和a,$1,$2,$3

谢谢

------解决方案--------------------
<script type="text/javascript">
function alerts(a,fun){
window.alert(a);
fun();
}
alerts(1,function(){alert(2);});
var string = "267";
var number = /(\d)(\d)(\d)/g;
alerts(string.match(number),function(){(function(a,b,c,d){return document.write(b);})(1,2,3,4)});
alerts(string.match(number),function(){(function(a,$1,$2,$3){return document.write($1);})(10,RegExp.$1,RegExp.$2,RegExp.$3)});
</script>
不明白你想做什么
------解决方案--------------------
你这是面试题吧

_alert=alert;
 alert=function(){
    var as=[].slice.call(arguments),f=as.pop();
    console.info((as.length?as[0]:'xx'),f)
   as.length?f.apply(f,  as[0].constructor==Array? as[0]:as  ):_alert(f);
 }

alert(1,function(){alert(2);});
var string = "267";
var number = /(\d)(\d)(\d)/;
alert(string.match(number),function(a,b,c,d){return document.write(b);});
alert(string.match(number),function(a,$1,$2,$3){return document.write($1);});