在 JavaScript 中循环广播组
我正在尝试循环遍历无线电组并验证用户是否已使用 Javascript 进行了选择。单选组是动态的,因此运行时字段名称未知,单选组的数量也未知。用户对每个单选按钮组进行选择后,然后处理表单。
I am trying to loop through Radio groups and validate that the user has made a selection using Javascript. The radio groups are dynamic so the field names are unknown at runtime, and the number of radio groups will also be unknown. After the user has made a selection for each radio group, then process the form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以有一个地图来查找未检查的字段名称。
那么
remaining
变量将是一个对象,其中保存用户尚未检查的单选按钮组的名称。如果它是空对象,则用户已选择所有组。
有关工作示例,请查看此处:http://jsfiddle.net/thai/qtJsJ/1/
You can have a map to find the field names that are not checked.
Then the
remaining
variable will be an object that holds the names of the radio group that the user hasn't checked.If it is an empty object, then the user has selected all groups.
For a working example, look here: http://jsfiddle.net/thai/qtJsJ/1/
您可以使用“input:radio”选择器选择所有单选按钮,然后确保为每个不同的名称设置一个值。
You could select all radio buttons using the 'input:radio' selector and then make sure that for each distinct name a value is set.
使用纯javascript你可以尝试类似的东西
with pure javascript you could try something like