问题
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