默认情况下,单选按钮不显示为选中
.我开始时没有默认选择,做了一些非常简单的 js 验证,但它不起作用.所以我选择只使用默认值,直到我弄清楚并发现发生了一些奇怪的事情.
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.
标记是有效的,我已经在 FF、Safari 和 Chrome 中尝试过.没有任何效果.
The markup is valid and I've tried in FF, Safari and Chrome. Nothing works.
我认为这是与 jQuery
库的冲突,因为当我删除调用脚本时问题就消失了.
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" />
如果你有多个同名的属性为 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>
这篇关于单选按钮“选中"属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!