您好我根据选择输入显示不同的序列导航。 这是我到目前为止要做的事情的例子:
<ul class="steps" id="dbleOpt">
<li class="active">Create<span class="chevron"></span></li>
<li>Fields<span class="chevron"></span></li>
</ul>
<ul class="steps" id="singleOpt">
<li class="active">Create<span class="chevron"></span></li>
<li>Welcome<span class="chevron"></span></li>
<li>Overview<span class="chevron"></span></li>
</ul>
这是我的javascript无效:
$(function () {
$('#singleOpt').hide();
$('#dbleOpt').show();
$('#Lists_opt_in').on("change",function () {
$('#dbleOpt').hide();
$('#singleOpt'+$(this).val()).show();
})
});
这里是选择输入....
<select id="Lists_opt_in" name="Lists[opt_in]" class="form-control has-help-text">
<option value="double" selected>Double opt-in</option>
<option value="single">Single opt-in</option>
</select>
答案 0 :(得分:3)
data
属性,如下面的代码段data
的{{1}}属性以显示
id
$(function() {
$('#singleOpt').hide();
$('#dbleOpt').show();
$('#Lists_opt_in').on("change", function() {
$('.steps').hide();
$('#'+$('option:selected', this).data('target')).show()
})
});
答案 1 :(得分:2)
为简单起见,只需尝试单个列表,然后使用jQuery的toggle()
方法切换可见性:
$(function () {
$('#Lists_opt_in').on("change",function () {
$('.dbleOpt').toggle();
$('.singleOpt').toggle();
})
});
&#13;
.hidden {
display: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="steps" id="dbleOpt">
<li class="active">Create<span class="chevron"></span></li>
<li class="dbleOpt">Fields<span class="chevron"></span></li>
<li class="singleOpt hidden">Welcome<span class="chevron"></span></li>
<li class="singleOpt hidden">Overview<span class="chevron"></span></li>
</ul>
<select id="Lists_opt_in" name="Lists[opt_in]" class="form-control has-help-text">
<option value="double" selected>Double opt-in</option>
<option value="single">Single opt-in</option>
</select>
&#13;