复选框表单验证 - 如何让用户选中4个复选框 [英] Checkbox form validation - how to make a user select 4 check boxes

查看:99
本文介绍了复选框表单验证 - 如何让用户选中4个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

复选框表格验证 - 如何让用户选择4个复选框?

我有几个复选框的问题以及如何要求用户检查2个复选框(不多也不少)?


这是我的表格:

< input type ="复选框"名称= QUOT;颜色" ID = QUOT; Q"值= QUOT; A" /> A< BR />

< input type ="复选框"名称= QUOT;颜色" ID = QUOT; Q2"值= QUOT; B" /> b< BR />

< input type ="复选框"名称= QUOT;颜色" ID = QUOT; Q3"值= QUOT; C" /> c< BR />

< input type ="复选框"名称= QUOT;颜色" ID = QUOT; Q4"值= QUOT; d" /> d< BR />


非常感谢。

Hello,
Checkbox form validation - how to make a user select 4 check boxes?
I have a question of a few checkboxes and how do I require a user to check 2 checkboxes (no more, no less)?

Here is my form:
<input type="checkbox" name="color" id="q" value="a" />A<BR />
<input type="checkbox" name="color" id="q2" value="b" />b<BR />
<input type="checkbox" name="color" id="q3" value="c" />c<BR />
<input type="checkbox" name="color" id="q4" value="d" />d<BR />

Thanks much.

推荐答案

hi,

,当你想要检查你有不同的可能性来实现你的目标:)你可以遍历元素并要求检查它们的组成部分。如果你找到2个已检查的你已经完成了......你现在可以打破循环并且一切正常...


你也可以在运行时响应点击事件。 。当点击/检查时,您可以将已检查元素的ID存储在js-object或您想要使用的任何内容中...然后...您正确地询问该对象的存储数据...以及您是否找到两个或多个存储的ID ...你已经完成了......


at the time you want to check you have different possibilities to achieve your goal :) you may loop through the elements and ask for check-attribs of them. if you find 2 checked ones you are done ... you may break the loop now and all is ok ...

you may also respond to the click-event at runtime ... when clicked/checked you might store the id of the checked element in an js-object or whatever you want to use for that ... then ... the right time you ask that object for stored data ... and if you find two or more stored ids ... you are done ...


这就是我在想的......


[HTML]

<! - 设置为''text''而不是''hidden''所以你可以看到它制造魔法! - >

< input id =" color0"名称= QUOT;颜色[] QUOT;类型= QUOT;文本"值= QUOT;" />

< input id =" color1"名称= QUOT;颜色[] QUOT;类型= QUOT;文本"值= QUOT;" />


< p>

< input id =" check0"类型= QUOT;复选框"的onclick = QUOT; pushChex(本);"值= QUOT; A" /> a< br />

< input id =" check1"类型= QUOT;复选框"的onclick = QUOT; pushChex(本);"值= QUOT; B" /> b< br />

< input id =" check2"类型= QUOT;复选框"的onclick = QUOT; pushChex(本);"值= QUOT; C" /> c< br />

< input id =" check3"类型= QUOT;复选框"的onclick = QUOT; pushChex(本);"值= QUOT; d" /> d< br />

< / p>


< script type =" text / javascript">

var
Here''s what I''m thinking...

[HTML]
<!-- Set to ''text'' instead of ''hidden'' so you can watch it make magic! -->
<input id="color0" name="color[]" type="text" value="" />
<input id="color1" name="color[]" type="text" value="" />

<p>
<input id="check0" type="checkbox" onclick="pushChex(this);" value="a" />a<br />
<input id="check1" type="checkbox" onclick="pushChex(this);" value="b" />b<br />
<input id="check2" type="checkbox" onclick="pushChex(this);" value="c" />c<br />
<input id="check3" type="checkbox" onclick="pushChex(this);" value="d" />d<br />
</p>

<script type="text/javascript">
var


chex = [null,null];

函数pushChex(
chex = [null, null];
function pushChex(


这篇关于复选框表单验证 - 如何让用户选中4个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆