Javascript jquery ui在同一页面中有多个弹出窗口
我使用jquery是为了在网站中弹出一些表单,问题是我希望能够弹出多个表单,我不知道如何让jquery使用多个id。守则:Javascript jquery ui在同一页面中有多个弹出窗口,javascript,jquery,forms,jquery-ui,Javascript,Jquery,Forms,Jquery Ui,我使用jquery是为了在网站中弹出一些表单,问题是我希望能够弹出多个表单,我不知道如何让jquery使用多个id。守则: $(function() { $( "#dialog:ui-dialog" ).dialog( "destroy" ); $( "#dialog-form" ).dialog({ autoOpen: false, height: 700, width: 750, modal: tr
$(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
等等?您应该能够添加多个由逗号分隔的选择器,例如
$( "#create-user1, #create-user2").dialog()
见:
编辑:在评论之后
这应该是可行的,它未经测试,也许不是最有效的,但这是一个开始
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()
在create-user-1中,添加一个
第一个内容到这里
,第二个第二个内容到这里
,您可以访问它的内容并使用适当的选择器
然后,
$(“#create-user1,#create-user2”).dialog()
你应该没事。不,但我希望能够动态地添加它们,使用一个未定义的数字。你的意思是:有一些id为create user的标签,这些数字是按顺序排列的,但是你不知道会有多少人?编辑答案,希望对你的问题有一个更有用的答案。