Radio Buttons“Checked”属性不起作用 [英] Radio Buttons "Checked" Attribute Not Working

查看:100
本文介绍了Radio Buttons“Checked”属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,单选按钮不会显示为已选中。我开始没有默认的选择做一些非常简单的js验证,它不工作。所以我选择使用默认值,直到我发现并发现了一些奇怪的事情。

这个标记是有效的,我尝试过FF,Safari和Chrome。什么都没有



我认为这是与 jQuery 库的冲突,因为当我删除调用脚本时问题消失。 / p>

< label>您要接受American Express吗?< / label> ;是< input id =amexstyle =width:20px; type ='radio'name ='Contact0_AmericanExpress'value ='1'/> No< input style =width:20px; '=''''''''''''''''''''''''''''='

解决方案

如果您使用checked属性具有多个相同名称,则会在页面上使用最后一次选中的广播。

 < form> 
< label>您要接受美国运通卡吗?< / label>
是< input id =amexstyle =width:20px; type =radioname =Contact0_AmericanExpress/>
也许< input id =amexstyle =width:20px; type =radioname =Contact0_AmericanExpresschecked =checked/>
无< input style =width:20px; type =radioname =Contact0_AmericanExpressclass =checkchecked =checked/>
< / form>


The radio button does not show up as checked by default. I started off without a default choice doing some very simple js validation and it wasn't working. So I opted to just use default values until I figured that out and discovered that something weird is going on.

The markup is valid and I've tried in FF, Safari and Chrome. Nothing works.

I think it's a conflict with the jQuery library because the problem goes away when I remove the call script.

<label>Do you want to accept American Express?</label> Yes
<input id="amex" style="width: 20px;" type='radio' name='Contact0_AmericanExpress' value='1' /> No
<input style="width: 20px;" type='radio' name='Contact0_AmericanExpress' class='check' value='0' checked="checked" />

解决方案

If you have multiple of the same name with the checked attribute it will take the last checked radio on the page.

<form>
<label>Do you want to accept American Express?</label>
Yes<input id="amex" style="width: 20px;" type="radio" name="Contact0_AmericanExpress"  />  
maybe<input id="amex" style="width: 20px;" type="radio" name="Contact0_AmericanExpress"  checked="checked" />  
No<input style="width: 20px;" type="radio" name="Contact0_AmericanExpress" class="check" checked="checked" />
</form>

这篇关于Radio Buttons“Checked”属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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