重置/取消选择选择选项
用法:
我有一个表单,其中有一个选择下拉列表,该下拉列表由另一个选择下拉列表控制。加载页面时(如果之前选择了值,PHP 会加载它们),选择下拉列表#2 隐藏多个选项(这有效)。当使用选择下拉列表 #1 选择特定选项时,选择下拉列表 #2 隐藏选项将变为可用(.show(),这有效)。
问题:(概述问题的示例:http://jsfiddle.net/RqhbY/7/)
当隐藏选项显示/可用并且选择一个选项,然后选择下拉列表 #1 更改隐藏下拉列表 #2 中的选项的值时,提交时将提交选定的隐藏值。
如何取消选择/重置现在隐藏的选定选项?
Usage:
I have a form that has a select drop-down that's controlled by another select drop-down. On loading the page (if values where selected before, PHP loads them) select drop-down #2 hides several options (this works). When selecting a particular option with select drop-down #1, select drop-down #2 hidden options become available (.show(), this works).
The problem: (An example to outline the problem: http://jsfiddle.net/RqhbY/7/)
When the hidden options are shown/available and one is selected and then the select drop-down #1 changes that value that hides the options in drop-down #2, On submission the selected hidden value gets submitted.
How can I un-select/reset the selected option that is now hidden?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://jsfiddle.net/RqhbY/8/
尝试更改:
使用:
更新< /strong>
好的,我在 IE 8 中测试了上面的代码,禁用的
仍然处于选中状态。但这似乎有效:
演示: http://jsfiddle.net/RqhbY/9/
请注意您可能想要更新
.filter()
调用以仅选择非禁用选项,但我会将其留给您。UPDATE
如果您在
演示:http://jsfiddle.net/RqhbY/10/
http://jsfiddle.net/RqhbY/8/
Try changing:
with:
UPDATE
OK, I tested the above code in IE 8 and the disabled
<option>
is still selected. This seemed to work however:Demo: http://jsfiddle.net/RqhbY/9/
Note that you may want to update the
.filter()
call to only select non-disabled options but I'll leave that for you.UPDATE
If you call
.attr('selectedIndex', -1)
on the<select>
element then you can have no<option>
s selected. The drop-down will not show a value but instead will be blank.Demo: http://jsfiddle.net/RqhbY/10/