禁用单选按钮单击上的下拉框
我有两个单选按钮和一个下拉框,如下所示。我想做的是: 1. 当选中“否”时,隐藏或灰显下拉框,然后 2. 当选中“是”时,显示下拉框。
任何指示将不胜感激!
<td colspan="4">
<input name="discount" type="radio" id="Yes" value="Yes" />Yes
<input name="discount" type="radio" id="No" value="No" checked="checked" />No<br />
<select class="purple" name="discountselection" id="discountselection">
<option value="1 Year" selected="selected">1 Year</option>
<option value="2 Years">2 Years</option>
<option value="3 Years">3 Years</option>
</select>
</td>
I have two radio buttons and a drop down box as you can see below. What I want to do is:
1. While no is checked, either hide, or grey out the drop down box, and
2. While yes is checked, show the drop down box.
Any pointers would be appreciated!
<td colspan="4">
<input name="discount" type="radio" id="Yes" value="Yes" />Yes
<input name="discount" type="radio" id="No" value="No" checked="checked" />No<br />
<select class="purple" name="discountselection" id="discountselection">
<option value="1 Year" selected="selected">1 Year</option>
<option value="2 Years">2 Years</option>
<option value="3 Years">3 Years</option>
</select>
</td>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
此外,还可以根据页面加载时选择的默认单选按钮设置下拉列表的显示样式或 HTML 中的禁用属性。
Also, set the dropdown's display style, or disabled property in HTML based on your default radiobutton selected on page load.
http://jsfiddle.net/uSmVD/
http://jsfiddle.net/uSmVD/
您需要将
select
控件设置为disabled
并使用与此类似的代码:请参阅 http://www.jsfiddle.net/A3BuQ/6/
参考:.one(), .removeAttr()
You need to set your
select
control todisabled
and use a similar code to this one:See http://www.jsfiddle.net/A3BuQ/6/
Ref.: .one(), .removeAttr()
这能行吗?
经过测试,效果很好。祝你好运。
Would this do it?
Tested, works great. Good luck.
你可以用 jQuery 隐藏它:
检查一下:
http://www.jsfiddle.net/cFUsU/
更新:添加 $(document).ready ();页面准备好时开始设置此代码以执行操作的方法
You can hide it with jQuery:
check it:
http://www.jsfiddle.net/cFUsU/
UPDATE: added $(document).ready(); method to start set this code to action when the page is ready