开发者

jquery ui multiple popups in the same page

i am using jquery in order to pop up some forms in a website, the problem is that i 开发者_运维知识库would like to be able to pop more than one form, and i have no idea how can i make the jquery take more than one id . the code:

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

can i make the button work for id's like: #create-user1, #create-user2 and so on?


you should be able to add multiple selectors separated by commas, eg

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

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

EDIT: after comments

This should work, it's untested and maybe not the most efficient, but its a start!

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() 


In create-user-1, add a <div id="create-user-1"><div id="a">First content goes here</div></div> and for the second one <div id="create-user-2"><div id="b">Second Content goes here</div></div> and you can access the contents of it and use a proper selector.

And then $( "#create-user1, #create-user2").dialog() and you should be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜