javascript - 在 jQuery 确认中显示选择菜单

标签 javascript jquery jquery-ui select jquery-confirm

我有一个 jQUery-confirm,我试图显示一些有选择的内容,但我的 select.selectMenu() 似乎不起作用,因为它显示在 jQUery-confirm 中。它只是显示默认选择。我可以轻松地在范围外的选择上调用 .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:

$(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();
            }

         });
     });
 });          

我如何让 jquery-confirm 显示像 selectmenu 这样的 jquery ui 小部件?

最佳答案

试试这个,你需要在 jconfirm 中添加 html 标记并初始化 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() {

            }
        });
    });
});  

关于javascript - 在 jQuery 确认中显示选择菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41610478/

相关文章:

javascript - 如何从 querySelectorAll 获取按钮类型

javascript - SVG.js:未定义referenceError SVG

jQuery:检查 jQuery 对象是否包含(包含)确切的 DOM 元素

javascript - 使可排序的元素可拖动,可以将其放在可放置的对象上,并在向后拖动时可以再次连接到列表

javascript - 多个对话框的 JQuery UI 对话框问题

javascript - 如何从二维数组创建html?

javascript - 如何将javascripts样式."property"设置为函数参数?

jquery - 背景图像无法正确呈现,其他图像不会出现在 Ipad 上

javascript - 如何使用 Angularjs + bootstrap 设置弹出窗口?

jquery-ui - 如何在显示效果期间制作 jQuery UI Dialog Modal?