2017-09-02 36 views
1

我點擊一個按鈕id="contact-submit"我的腳本運行,它發送一條消息鬆弛。點擊按鈕顯示彈出框,是/否選項。 jquery/HTML

我想要的是用戶點擊按鈕後我想要一個彈出框顯示問你確定嗎?是/否

Yes = Sends the message as it does now 
No = Closes the popup with no action 

任何人都幫我出去我一直在努力幾個小時!

HTML

<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Log</button> 

腳本

$(document).ready(function(){ 
     $('#contact-submit').on('click',function(e){ 
      e.preventDefault(); 
      var url = 'https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxx' 
      var text = 'Some Text Here' 
      $.ajax({ 
       data: 'payload=' + JSON.stringify({ 
        "text": text 
       }), 
       dataType: 'json', 
       processData: false, 
       type: 'POST', 
       url: url 
      }); 
     }); 
    }); 

回答

2

您可以使用JavaScript的默認confirm彈出這樣的:

if(!confirm("Are you sure?")) 
    return false; 

請參見下面的演示:

$(document).ready(function() { 
 
    $('#contact-submit').on('click', function(e) { 
 
    e.preventDefault(); 
 
    if(!confirm("Are you sure?")) 
 
     return false; 
 
    var url = 'https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxx' 
 
    var text = 'Some Text Here' 
 
    $.ajax({ 
 
     data: 'payload=' + JSON.stringify({ 
 
     "text": text 
 
     }), 
 
     dataType: 'json', 
 
     processData: false, 
 
     type: 'POST', 
 
     url: url 
 
    }); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Log</button>

+1

你的先生/女士應該有一個勳章:d優秀的 - 非常感謝你!會提高一次,我可以 –

+0

對不起,一個簡單的問題,沒有大問題,如果它不容易完成。相當迂腐,但它說,確定/取消 - 有沒有一種快速的方法來改變這是/否:) –

+0

不幸的是,不認爲'確認'可以修改... – kukkuz