【问题标题】:jquery ui multiple popups in the same pagejquery ui在同一页面中的多个弹出窗口
【发布时间】:2011-06-30 13:53:40
【问题描述】:

我正在使用 jquery 来在网站中弹出一些表单,问题是我希望能够弹出多个表单,但我不知道如何让 jquery 占用多个表单ID 。代码:

    $(function() {

    $( "#dialog:ui-dialog" ).dialog( "destroy" );


    $( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 700,
        width: 750,
        modal: true,
        buttons: {

            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
        close: function() {
            allFields.val( "" ).removeClass( "ui-state-error" );
        }
    });

    $( "#create-user" )
        .button()
        .click(function() {
            $( "#dialog-form" ).dialog( "open" );
        });
});

我可以让按钮适用于以下 ID:#create-user1#create-user2 等吗?

【问题讨论】:

    标签: javascript jquery forms jquery-ui


    【解决方案1】:

    您应该能够添加多个用逗号分隔的选择器,例如

    $( "#create-user1, #create-user2").dialog() 
    

    见:http://api.jquery.com/multiple-selector/

    编辑:在 cmets 之后

    这应该可行,它未经测试,也许不是最有效的,但它是一个开始!

    var count = 1;
    var selectorString = "";
    while ($("#create-user" + count).length > 0) { // .length check to see if the element is present
        count++;
        selectorString += "#create-user" + count + " ";
    }
    $( selectorString ).dialog() 
    

    【讨论】:

    • 不,但我希望能够使用未定义的数字动态地添加它们
    • 你的意思是这样的:有一些 id 为 create-user 的标签,其中的数字是按顺序排列的,但你不知道会有多少?
    • 编辑了答案,希望对您的问题有更有用的答案。
    【解决方案2】:

    在 create-user-1 中,添加 <div id="create-user-1"><div id="a">First content goes here</div></div> 和第二个 <div id="create-user-2"><div id="b">Second Content goes here</div></div>,您可以访问它的内容并使用适当的选择器。

    然后$( "#create-user1, #create-user2").dialog() 你应该没问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多