Is it possible to make Combo box option unselectable without disabling it? [duplicate]

倖福魔咒の 提交于 2019-12-14 04:25:33

问题


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

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