问题
Possible Duplicate:
Disable select option in IOS Safari
Since safari mobile browser do not support disabled="disabled" attribute hence I am looking for other way to make select box option look disabled may be through events or some other way around ?
<select>
<option value="monthly" disabled="disabled">Month</option> <!-- do not get disabled on iphone -->
<option value="yearly">Yearly</option>
</select>
Thanks.
回答1:
You could add a:
onchange="selectValidate(this, 1)"
To your HTML and then in javascript:
function selectValidate(refSelect, defaultIndex)
{
if(refSelect.options[refSelect.selectedIndex].hasAttribute("disabled"))
{
alert("You can't select that value");
refSelect.selectedIndex=defaultIndex;
}
}
Not tested but it should work.
FOR THE LOOK AND FEEL:
I think that you can use the CSS to specify your disabled items.
Example:
select option[disabled]
{
background-color:#FBFBFB;
}
It may work on Safari as well since it's supposed to support CSS.
回答2:
Are you willing to use a jquery combo box plugin? I googled for this one and it seems to fit your requirements.
来源:https://stackoverflow.com/questions/8871138/is-it-possible-to-make-combo-box-option-unselectable-without-disabling-it