2017-01-03 24 views
1

我一直在jquery上工作過去幾個月,喜歡在上面工作新事物。Jquery中的自定義警報不會等待並返回點擊事件

最近我堅持使用一個模式彈出,我做了一個自定義的警報(使用語義UI,不使用jQuery UI的)....

我想執行一個點擊事件(這完美的作品) ..但在此之前,我想叫這個自定義警報

定製,我提出警報是

function confirmAlert(msg,OnSuccess){ 
    $('<div style="width:30%;height:15%;margin-left:-15em;" align="center" id="divretwhlsucc" class="ui tiny modal"> <div class="content"> <i class="checkmark big green box icon"></i>'+msg+'</div> <div class="actions"> <div class="ui black deny button">No</div><div class="ui positive right icon button">OK</div></div></div/>') 
    .modal({ 
    closable : false, 
    onDeny : function(){ 
    }, 
    onApprove : function() { 
     return true; 
    } 
    }) 
    .modal('show'); 
} 

此模式彈出,當我嘗試以完美的click事件(這是寫在下面)

$("#btnwhlsuppdel").click(function(){ 
     debugger; 
     confirmAlert("Are you sure you want to delete?",function(){ 
      debugger; 
      var a = []; 
      var info = []; 
      var cboxes = $('input[name="suppcheck[]"]:checked'); 
      var len = cboxes.length; 
      for (var i=0; i<len; i++) { 
      a[i] = cboxes[i].value; 
      $("#hiddwhlsuppgrp").val(a); 
      } 
     }); 
     }); 

現在,即使我觸發事件,它也不會等待customAlert上的onApprove函數,並直接執行。

我希望customAlert的行爲類似,如果我批准要執行的操作,則應單擊事件觸發,否則應返回false。

任何答案都是非常讚賞,因爲我會在jquery中學到更多!

謝謝!

+0

http://stackoverflow.com/questions/3519861/yes-or-no-confirm-box-using-jquery – Bharat

+0

也許你想要的是這裏實現.. – Bharat

+0

解決方案:你得把兩個對話方框中,一個用於批准操作,另一個將在您的批准後顯示。 –

回答

0

你可以試試下面的波紋管。在此代碼中,您需要將成功功能分配到onApprove回調。

function confirmAlert(msg,OnSuccess){ 
    $('<div style="width:30%;height:15%;margin-left:-15em;" align="center" id="divretwhlsucc" class="ui tiny modal"> <div class="content"> <i class="checkmark big green box icon"></i>'+msg+'</div> <div class="actions"> <div class="ui black deny button">No</div><div class="ui positive right icon button">OK</div></div></div>') 
    .modal({ 
    closable : false, 
    onDeny : function(){ 
    }, 
    onApprove : OnSuccess 
    }) 
    .modal('show'); 
} 

$("#btnwhlsuppdel").click(function(){  
     confirmAlert("Are you sure you want to delete?",function(){   
      var a = []; 
      var info = []; 
      var cboxes = $('input[name="suppcheck[]"]:checked'); 
      var len = cboxes.length; 
      for (var i=0; i<len; i++) { 
      a[i] = cboxes[i].value; 
      $("#hiddwhlsuppgrp").val(a); 
      } 
     }); 
     }); 
+0

沒有工作。儘管如此,謝謝你的努力 –