2016-03-15 106 views
0

我使用$("selector").is(":visible")來檢查元素的可見性。

但是,當使用模態(引導模式)中的元素時,這只是簡單的故障。

儘管我找到一種方法使用$("selector").css("display")作爲臨時工,但這仍然是一個值得解決的問題。

請檢查此jsiddle page瞭解更多有關此問題的信息。

回答

0

發生這種情況是因爲執行代碼時未顯示模態。有一個動畫。這裏是修改後的代碼來證明這一點。你可以使用模態的事件來完成你想要的東西:

window.setTimeout(function() { 
    console.log(labelError.is(":visible")); 
    console.log(labelError.css("display")); 
    labelError.show(); 

    console.log(labelError.css("display")); 
    console.log(labelError.is(":visible")); 
},500); 

看到修改後的jsfidle頁面在這裏:https://jsfiddle.net/pbjd2bz6/

0

由於引導3.0,我們可以使用(「shown.bs.modal」,功能(五){

見的jsfiddle https://jsfiddle.net/jn111sum/4/

$("#generator").on('shown.bs.modal', function (e) { 
     var labelError=$("#phrasesError"); 
     $("#phrasesError").fadeOut(); 
    console.log("this is where the useful infos begin"); 
    console.log(labelError.is(":visible")); 
    console.log(labelError.css("display")); 
    labelError.show(); 
    console.log(labelError.css("display")); 
    console.log(labelError.is(":visible")); 
}); 

希望幫助