JS confirm, some browsers will be directly shielded, resulting in the function can not be used, recommend the use of JQuery UI dialog function, perfect replacement
Confirm function
1,html Code
<div id= "Confirm_dialog" title= "hint" style= "display:none;" >
</div>
Put the above code in a common place
2, Analog confirm JS code
var common = {
Confirm_act:function (Dialog_id,msg,callback) {
$ ("#" +dialog_id). HTML ("<p class= ' message ' >" +msg+ "</p>");
$ ("#" +dialog_id). Dialog ({
Resizable:false,
Modal:true,
Overlay: {
BackgroundColor: ' #000 ',
opacity:0.5
},
Buttons: {
' Confirm ': function () {
Callback.call ();
$ (This). dialog (' Close ');
},
' Cancel ': function () {
$ (This). dialog (' Close ');
}
}
});
}
}
Defines a method confirm_act, put in the public JS file, the first parameter, the ID of the bomb layer, the second parameter is the prompt message, the third is the callback function.
Note that when invoking the callback function, use the call () function of JS, which can take parameters or include callback functions.
3, Callback JS code
var recommend = {
Delete:function (Url,obj)
{
$.ajax ({
Url:url,
Type: "Get",
Success:function (data)
{
............ Omitted..........
}
});
}
}
4, How to call
$ ('. Recommended_delete '). Click (function () {
var obj = this; Renaming
Common.confirm_act (' Confirm_dialog ', $ (obj). attr (' msg '), function () {Recommend.delete ($ (obj). attr (' url '), obj)});
});
Note that if you want to pass this in the function, note that you want to redefine it.