2

我想要做的是将代码中的每个警报更改为自定义警报(“您使用警报”);

var hardCodedAlert = alert; //I know this won't work.But what to do ?
window.alert=function(){
if(this.count == undefined)
this.count=0;
this.count=this.count+1;
if(this.count == 1)
hardCodedAlert("You used alert");
};
4

1 回答 1

1

是的,您可以这样做(例如):

var oldalert = window.alert;
window.alert= function alert(t){
  alert.count = !alert.count ? 1 : alert.count + 1;
  oldalert(t+' - That\'s alert nr '+alert.count);
};

看到这个jsfiddle

于 2012-04-22T10:12:50.477 回答