单选按钮验证 - 不是USUSAL [英] Radio Button validation - NOT USUSAL

查看:57
本文介绍了单选按钮验证 - 不是USUSAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:


有四个问题,每个问题都有用于标记选项的单选按钮

" yes"或不。每个FORM我只需要一个是(所以如果2标记为是,

则不需要任何其他的等等)因此验证必须寻找

a single yes ,然后警告,如果有多个....问题是,我

似乎无法让它工作。

Scenario:

There are four questions, each with radio buttons to mark the choice
"yes" or "no". I need only one yes per FORM (so if 2 is marked yes,
there is no need for any others to be, etc) so validation must look for
a single yes, then alert if there is more than one....problem is, I
can''t seem to get it to work.

推荐答案

于2005年8月在comp.lang.javascript中写道
wrote on 08 mrt 2005 in comp.lang.javascript:
情景:
是。或不。每个FORM我只需要一个是(所以如果2标记为是,
则不需要任何其他的等等)因此验证必须查找
一个是,然后警告是否有更多....问题是,我似乎无法让它工作。
Scenario:

There are four questions, each with radio buttons to mark the choice
"yes" or "no". I need only one yes per FORM (so if 2 is marked yes,
there is no need for any others to be, etc) so validation must look for
a single yes, then alert if there is more than one....problem is, I
can''t seem to get it to work.




如果你给他们相同的名字,只有一个是肯定的。


< form>

< input type =''radio''name =''myRadio''value ='' 1''检查>一个< br>

< input type =''radio''name =''myRadio''value ='''2''>两个< br>

< input type =''radio''name =''myRadio''value ='''3''>三< br>

< input type =''radio''name =''myRadio''value ='''4''>四个< br>

< / form>


-

Evertjan。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)



If you give them the same name, only one will be yes.

<form>
<input type=''radio'' name=''myRadio'' value=''1'' checked> one<br>
<input type=''radio'' name=''myRadio'' value=''2''> two<br>
<input type=''radio'' name=''myRadio'' value=''3''> three<br>
<input type=''radio'' name=''myRadio'' value=''4''> four<br>
</form>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)


但是我需要标记为no的那些。 (3个剩下的问题)捕获

没有作为答案....

But I need to have those marked "no" (3 remaining questions) to capture
no as the answer....


;)jepp,很奇怪。有一些方法可以检查和发现但是我已经没有工作了吗?b $ b因为''收音机'看起来很糟糕而且''按钮''真的出来了

更容易

要处理如果你写一个小包装器,你的

按钮栏中只有一个可以是

已检查。 (比如在数组中保存名称并在onClick上使用一个函数

切换

将它们改为''off-state'',f.ex。改变值或颜色和启用

号码原来

点击了。)

=> onclick =" myfunc(buttname)"

==> function myfunc(name){

for(var ii = 0; ii< nr_of_buttons; ii ++){

if(name == name [ii]){highlight}

其他{关闭}

}

}


同样适用于收音机,但作为我认为他们看起来不性感

无论如何...

;) jepp, weird. There are some ways to check and find out but i''ve
never worked
that really out because ''radios'' look pretty shitty and ''buttons''
are much easier
to handle if you write a little wrapper that only one of Your
buttons bar can be
checked. (like hold the names in an array and onClick use a function
to switch
them to ''off-state'', f.ex. change value or color and enable the
number originally
was clicked on.)
=> onclick="myfunc(buttname)"
==> function myfunc(name){
for(var ii=0;ii<nr_of_buttons;ii++){
if(name==name[ii]){ highlight }
else{turnoff }
}
}

same works with radios too, but as i think they dont look sexy
anyhow...


这篇关于单选按钮验证 - 不是USUSAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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