jQuery Deferred and Dialog box

前端 未结 3 1911
function ValidateField(){
var bAllow= true;

    //some checking here

if (bAllow == true && apl.val().trim() == \"\")
{ 
    showDialog(); 
    showDialog()         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 05:51

    I have created this JSFIDDLE and changed the boolean parse because that was blowing up. Thanks, Pierre! This has saved me a lot of time.

    javascript:

    function confirmation(question) {
    var defer = $.Deferred();
    $('
    ') .html(question) .dialog({ autoOpen: true, modal: true, title: 'Confirmation', buttons: { "Yes": function () { defer.resolve("true");//this text 'true' can be anything. But for this usage, it should be true or false. $(this).dialog("close"); }, "No": function () { defer.resolve("false");//this text 'false' can be anything. But for this usage, it should be true or false. $(this).dialog("close"); } }, close: function () { //$(this).remove(); $(this).dialog('destroy').remove() } }); return defer.promise(); }; function onclick(){ var question = "Do you want to start a war?"; confirmation(question).then(function (answer) { console.log(answer); var ansbool = (String(answer) == "true"); if(ansbool){ alert("this is obviously " + ansbool);//TRUE } else { alert("and then there is " + ansbool);//FALSE } }); } $("#item").on('click', onclick);

    HTML:

    
    

提交回复
热议问题