【发布时间】:2017-03-10 05:08:48
【问题描述】:
在多步骤表单中,我使用下面的代码转到表单的下一部分或上一部分(只有一个步骤可见,其他步骤隐藏):
$(".next").click(function(){
if (form.valid() === true){
if ($('#one').is(":visible")){
current_fs = $('#one');
next_fs = $('#two');
}else if($('#two').is(":visible")){
current_fs = $('#two');
next_fs = $('#three');
}
next_fs.show();
current_fs.hide();
}
});
$('#previous').click(function(){
if($('#two').is(":visible")){
current_fs = $('#two');
next_fs = $('#one');
}else if ($('#three').is(":visible")){
current_fs = $('#three');
next_fs = $('#two');
}
next_fs.show();
current_fs.hide();
});
如果我有一个 3 步表单,此代码运行良好,但我想使用数组修改我的代码以转到下一步或上一步。
我尝试使用像 var pages = ["#one","#two","#three"] 这样的数组并使用,例如 if ($(pages[0]).is(":visible")) 而不是 if ($('#one').is(":visible"))
如何修改此代码以使其可扩展(例如,如果我想添加更多页面)
谢谢
【问题讨论】:
-
请发布您正在使用的html。这有助于我们提供完美的解决方案
-
html 代码是一个带有一些 fieldset 标签的表单。每个字段集都有一个 id 女巫是 pages 数组。使用 css 所有字段集都设置为 display:none 除了 id="one"
-
如果有人为您工作,请不要忘记接受答案...如果您不这样做,您会发现人们越来越不可能提供帮助:)
标签: javascript jquery arrays forms