Disabled option in Firefox bug

六月ゝ 毕业季﹏ 提交于 2019-12-22 06:01:33

问题


I was creating some form when I saw that in Firefox. In a select box, if you add a disabled option as first choice... it select the next available option

<option disabled="disabled" value="false">Choose option</option>
<option value="1">Value 1</option>

It will select "Value 1" when the page is loaded.

Why every browser will select the disabled one by default and Firefox not?

Load this in Firefox : http://jsfiddle.net/6WjgZ/1/

and other browser you'll notice that Firefox bypass the disabled one and select the "Value 1" by default.


回答1:


Assuming you want a workaround, run this code on DOM Load (or body load) to fix it in Firefox

document.getElementById("mySel").selectedIndex = 0;

http://jsfiddle.net/6WjgZ/2/

Not sure if this can be called a bug (more of a behavior style), if you think about it, FF doesn't let you choose disabled items. Neither does other browsers (except IE) but then, they choose to behave differently for the initial load.




回答2:


you could use optgroup if you want a non-selectable option, or simply use the value for form validation.

if all you want is the disabled style, you could give the option a class and change it with css

i think ff behaviour is right, a disabled option should not be a valid option. you can always file it as a bug in mozilla



来源:https://stackoverflow.com/questions/6903131/disabled-option-in-firefox-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!