gpt4 book ai didi

jquery - 如何使用Jquery获取选中的复选框和相应的信息?

转载 作者:行者123 更新时间:2023-12-01 02:57:14 24 4
gpt4 key购买 nike

我在页面上有一些带有标题的复选框,我想使用 jQuery 获取所有选中的复选框以及该复选框的对应信息?

最终,我想提交一个包含用户选择的所有内容的表单。但由于表单不知道,所以我需要在用户单击打开表单的按钮时获取信息。

谢谢!

<section id="myoptions">

<label for="123">
<div class="thisineed">Want this text</div>
<div><input type="checkbox" id="123"></div>
<div class="thisaswell">This one I want as well</div>
</label>

<label for="124">
<div class="thisineed">Want this text</div>
<div><input type="checkbox" id="124"></div>
<div class="thisaswell">This one I want as well</div>
</label>

</section>

最佳答案

您可以使用它来访问选中的复选框:

$('input[type=checkbox]:checked').each(function(){
console.log(this);
});

这是给您的一个例子。有点不清楚您在寻找什么,但请检查一下:

$('#get_form').click(function () {
$('input[type=checkbox]:checked').each(function () {
console.log(my_form);
var somevalue = $(this).parent().next('.thisaswell').text();
console.log(somevalue);
$('#my_form').append('<input type="hidden" value="'+somevalue+'" />')
});
});

还有这个 demo 以我作为示例添加的表单生成隐藏输入,并在后面添加 div 中的文本。

关于jquery - 如何使用Jquery获取选中的复选框和相应的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18273886/

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