2013-11-02 98 views
3

當我點擊類'alert3'的按鈕時出現的提示彈出不會關閉。在bootbox中提示彈出不關閉

<a href="#" class="btn btn-primary btn-lg alert3">CLICKMEMEMEMEMEME</a> 

,這是我調用該函數:

<script> 

    $(document).on("click", ".alert3", function(e) { 
     bootbox.prompt("What is your name?", function(result) {     
      if (result === null) {            
       Example.show("Prompt dismissed");        
      } else { 
      Example.show("Hi <b>"+result+"</b>");       
      } 
     }); 
    }); 
</script> 

回答

5

彈出窗口不會關閉,因爲你在回調函數中有一個錯誤,所以它崩潰之前bootbox可以使彈出消失。

最好的猜測是Example未在您的代碼中定義。也許你把它放在Bootbox網站上,它們使用的是一個名爲Example的JavaScript對象。 如果你想顯示你的回調函數的結果,你可以添加到您的HTML:

<a href="#" class="btn btn-primary btn-lg alert3">CLICKMEMEMEMEMEME</a><br/> 
<p id='result'></p> 

,然後改變你的JavaScript:

<script> 
$(document).on("click", ".alert3", function(e) { 
    bootbox.prompt("What is your name?", function(result) { 
     if (result === null) { 
      $('#result').html("Prompt dismissed"); 
     } else { 
      $('#result').html("Hi <b>"+result+"</b>"); 
     } 
    }); 
}); 
</script> 
+0

謝謝,這幫助! –

1

提示彈出在bootbox.js

這不起作用,因爲Example函數沒有在那裏定義。我們需要先定義它們,使用當前選擇器值和與它們相關的文本。這裏用$(「#result」)來顯示錯誤信息rticular div。

的html代碼:

<p>Click here-><a class="alert" href=#>Alert!</a></p><p id='result'</p> 

代碼:

var Example = (
function() 
{ 
"use strict"; 

var elem, 
    hideHandler, 
    that = {}; 

that.init = function(options) { 
    elem = $(options.selector); 
}; 
that.show = function(text) { 
    clearTimeout(hideHandler); 

    $("#result").html(text); 
    $("#result").fadeIn(); 

    hideHandler = setTimeout(function() { 
     that.hide(); 
    }, 4000); 
}; 

that.hide = function() { 
    $("#result").fadeOut(); 
}; 

return that; 
}());