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>
这篇关于单选按钮“选中"属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:单选按钮“选中"属性不起作用
基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
