The example in this article describes the method of jquery UI dialog instead of confirm. Share to everyone for your reference, specific as follows:
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)
{......
Omit; ...}}, or ...}
4, How to call
$ ('. Recommended_delete '). Click (function () {
var obj = this; Rename
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 .
More about jquery related content readers can view the site topics: "jquery common Plug-ins and Usage summary"
I hope this article will help you with the jquery program design.