[英]Radio input checked
I have 2 radio inputs.我有 2 个无线电输入。 A,B
甲,乙
I an trying to make A as a selected radio by default.我试图将 A 默认设置为选定的收音机。 And I want the following behavior: when A get hidden then B should get checked by default.
我想要以下行为:当 A 被隐藏时,B 应该默认被选中。
This is what I tried.这是我尝试过的。 Please take a look.
请看一下。
<div >
<input type="radio" checked="checked" value="0" name="a" />
<strong>A</strong>
</div>
<div>
<input type="radio" checked="" value="1" name="b" />
<strong>
B
</strong>
</div>
<input type="text" onfocus="Javascript:document.forms[1].opt_payment[1].checked=true;" maxlength="20" value=" " name="" />
Thanks谢谢
对 A 使用属性checked="checked"
。此外,如果您希望一次只检查 A 和 B 中的一个,请为它们提供相同的名称但不同的值。
checked=""
means "Should be checked by default". checked=""
表示“应该默认选中”。 There is no way to have the attribute present but indicate "not checked".没有办法让属性存在,但表示“未选中”。
If you don't want a form control to be checked by default then do not include any checked attribute for it如果您不希望默认检查表单控件,则不要为其包含任何已检查的属性
<div >
<input id="radioA" type="radio" checked="checked" value="0" name="a" />
<strong>A</strong>
</div>
<div>
<input id="radioB" type="radio" value="1" name="b" />
<strong>
B
</strong>
</div>
Script:脚本:
if($("#radioA").is(":hidden")){
$("#radioB").attr("checked","checked");
}
you can also use你也可以使用
$("#radioB").attr("checked",true);
or use prop
for jquery version > 1.6或对 jquery 版本> 1.6 使用
prop
$("#radioB").prop("checked",true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.