gpt4 book ai didi

javascript - jquery 使用下一个和上一个按钮显示隐藏表单字段

转载 作者:行者123 更新时间:2023-11-30 08:46:21 25 4
gpt4 key购买 nike

我有一个表格,里面有 100 个问题..和复选框或单选按钮作为回答问题的选项..

 <b style="font-weight:bold">1.How long have you been working in field of Programming?</b><br/>
<input type="radio" name="1" value="Less than 2 years" style="cursor:pointer">
<span style="display: inline-block;font-size: 13px;position: relative;top: -2.5px;">Less than 2 years</span>

<input type="radio" name="1" value="3-5 years" style="cursor:pointer">
<span style="display: inline-block;font-size: 13px;position: relative;top: -2.5px;">3-5 years</span>

<input type="radio" name="1" value="6-10 years" style="cursor:pointer">
<span style="display: inline-block;font-size: 13px;position: relative;top: -2.5px;">6-10 years</span>

<input type="radio" name="1" value="11-15 years" style="cursor:pointer">
<span style="display: inline-block;font-size: 13px;position: relative;top: -2.5px;">11-15 years</span>

上面的 html 是我在 100 个问题中的第一个问题....所以为此我决定......创建一个下一个previous 按钮一次在屏幕上显示 10 个问题?

有什么建议或帮助会很有帮助吗?..提前致谢..

最佳答案

这是我能得到的最简单的方法。

HTML:
为页面添加 div(第一页有一个额外的 active 类)

<div class="page active">
<!-- A set of questions go here -->
</div>

<div class="page">
<!-- Another set of questions go here -->
</div>
...

CSS:

.page { display: none; }
.active { display: inherit; }

jQuery:

$("#prev").on("click", function(){
if($(".page.active").index() > 0)
$(".page.active").removeClass("active").prev().addClass("active");
});
$("#next").on("click", function(){
if($(".page.active").index() < $(".page").length-1)
$(".page.active").removeClass("active").next().addClass("active");
});

完成了!

在这里摆弄这个例子: http://jsfiddle.net/V8LCL/

关于javascript - jquery 使用下一个和上一个按钮显示隐藏表单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21713569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com