Radio Buttons quot;Checkedquot; Attribute Not Working(单选按钮“选中属性不起作用)
问题描述
默认情况下,单选按钮不显示为选中
.我开始时没有默认选择,做了一些非常简单的 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>
这篇关于单选按钮“选中"属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:单选按钮“选中"属性不起作用


- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01