2016-12-17 62 views
0

我試圖讓我的確認看起來更好,但是當我試圖做它不能正常工作。Django - 確認與jquery bootbox

它顯示我一切正常,但它自動單擊「確定」,不讓我,如果我想確認與否。

這裏就是我的了:

我的模板:

<td > <a href="{% url 'edit' item.id %}" class="confirm" > <img class="autoResizeImage" src="http://www.free-icons-download.net/images/edit-icon-1901.png"/ > </a> </td> 

我的JS:

$(document).on('click', '.confirm', function(){ 
bootbox.confirm("Are you sure?", function(result){ alert('This was logged in the callback: ' + result); }); 

注:

只有當我加我<a href="{% url 'edit' item.id %}"></a>如果我發生有這樣簡單的<button class="confirm" > click me </button>效果很好。

我在做什麼錯?

基本上,當我點擊「編輯」,讓我的onclick jquery function出現我的確認,但它會自動將我重定向到我的<a href="{% url 'edit' item.id %}"></a>,我想要重定向我,當我點擊「確定」按鈕。

回答

0

您需要防止您的click事件從triiggering錨以及其傳播,如果你的bootbox有點擊處理了DOM treee,你可以嘗試

$(document).on('click', '.confirm', function(e){ 
    e.preventDefault(); 
    e.stopPropagation(); 
    bootbox.confirm("Are you sure?", function(result){ 
     alert('This was logged in the callback: ' + result); 
    }); 
    //rest of the code for this click 
});