jquery UI Dialog Alternative Confirm example

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.