2016-11-28 48 views
-1

試圖使用Bootbox確認,但我開始用bootbox.alert()進行測試,但它不起作用。Bootbox警告不起作用

我確認我已經bootstrab.cssbootstrab.js的jquery.js和 - 包含在網頁標題bootbox.min.js

<link href="{% static "css/patients.css" %}" rel="stylesheet"> 
<link href="{% static "css/bootstrap.css" %}" rel="stylesheet"> 

<link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet"> 
<link href="{% static "css/jquery-ui.min.css" %}" rel="stylesheet"> 
<link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet"> 
<link href="{% static "css/bootstrap-datetimepicker.min.css" %}" rel="stylesheet"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 

這裏我點擊時想要生成警報的按鈕:

<form id='form' name='delete' action="{% url 'delete_person' person.id %}" 
      method='POST'> 

    {% csrf_token %} 

    <button type='submit' class='btn btn-xs btn-link icon'><i class='glyphicon glyphicon-remove'></i></button> 
</form> 

在同一的.html文件我有:

<script type="text/javascript"> 
    $(document).ready(function(){ 
      $('.btn').on('click' , function(){ 
       bootbox.alert("hello there!"); 
         }); 
       });</script> 

當我點擊按鈕,什麼都沒有發生,

我證實,我的瀏覽器都能夠從CDN下載內容, 不知道哪裏出了問題。

+0

什麼? – circusdei

+0

我在控制檯中看不到任何與bootbox相關的東西,我使用了firefox控制檯 - > js並使用過濾器在Bootbox上進行過濾 –

+0

您正在收聽表單提交按鈕,並且您已經爲其分配了一個操作。看看這個答案類似的問題:http://stackoverflow.com/a/27328602/185034 – Paul

回答

0

我找到了答案here

這個工作對我來說:在控制檯

<script type="text/javascript"> 
$(document).ready(function(){ 
$(".btn#del").click(function(e) { 
    e.preventDefault(); 
    var lHref = $('form#form1').attr('action'); 
    bootbox.confirm("Are you sure?", function(confirmed) { 
     if(confirmed) { 
      window.location.href = lHref; 
     } 
    }); 
}); 
}) 
</script> 

<button type='submit' onclick="bootbox.confirm();" id="del" class='btn btn-xs btn-link icon'><i class='glyphicon glyphicon-remove'></i></button> 
    </form></td>