2017-01-12 22 views
1

我有一個jQuery-confirm和im試圖顯示一些內容有一個選擇,我的select.selectMenu()似乎並不工作,因爲它顯示在jquery確認。它只顯示默認選擇。我可以輕鬆地在選擇範圍外的select上調用.selectMenu(),它將從select更改爲selectmenu。例如:在jQuery中顯示selectmenu確認

HTML:

<div id="aDiv"> 
    <select id="aSelect"> <option value="1"> 1 </option></select> 
</div> 
<button type="button" id="aButton">Click </button> 

CSS:

#aDiv { 
    display: none; 
} 

JS:

如何讓jQuery的確認顯示jQuery UI的小部件一樣selectmenu?

回答

1

試試這個,你需要添加HTML標記內jconfirm並初始化selectMenu插件,它能夠更好在內容中寫入標記而不是在外部定義它。

$(document).ready(function() { 
    // $('#aSelect').selectMenu(); 
    $('#aButton').on("click", function() { 
     $.confirm({ 
      title: 'Hello', 
      content: function(){ 
       return $('#aDiv').html(); // put in the #aSelect html, 
      }, 
      onContentReady : function() { 
       this.$content.find('#aSelect').selectMenu(); // initialize the plugin when the model opens. 
      }, 
      onClose : function() { 

      } 
     }); 
    }); 
}); 
+0

但現在我有一個新的問題。下拉菜單位於jquery內容窗口的後面,請看這裏:http://imgur.com/a/ayoJz。另外selectMenu()需要.selectmenu():) – jones

+0

我在想也許'.ui-selectmenu-menu { \t \t z-index:9999; \t \t}在CSS中會解決問題,但我錯了,它沒有工作。 – jones

+0

如何獲得jquery的z-index-confirm $ .confirm窗口? – jones

1

請嘗試以下方法:

你已經錯過了ID

$(document).ready(function() { 
    $('#aSelect').selectMenu(); 
    var divVar = $('#aDiv'); 
    $('#aButton').on("click", function() { 
     $.confirm({ 
      title: 'Hello', 
      content: '', 
      onOpen : function() { 
       divVar.show(); 
       this.setContent(divVar); 
      }, 
      onClose : function() { 
       divVar.hide(); 
      } 

     }); 
    }); 
});  
+0

忘了加上「#」的例子中,我已經他們在我的原代碼,編輯它有些工作的問題 – jones