是否可以在不禁用组合框选项的情况下取消选择? [英] Is it possible to make Combo box option unselectable without disabling it?

查看:109
本文介绍了是否可以在不禁用组合框选项的情况下取消选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

禁用IOS Safari中的选择项


由于safari手机浏览器不支持disabled =disabled属性,因此我正在寻找其他方式来使选择框选项看起来被禁用,可能是通过事件或其他方式?

 <选择> 
< option value =monthlydisabled =disabled> Month< / option> <! - 不要在iphone上禁用 - >
< option value =annual>年度< / option>
< / select>

谢谢。

解决方案你可以添加:

  onchange =selectValidate(this,1)

添加到您的HTML然后添加到javascript中:

 函数selectValidate(refSelect,defaultIndex)
{
if(refSelect.options [refSelect.selectedIndex] .hasAttribute(disabled))
{
alert (你不能选择那个值);
refSelect.selectedIndex = defaultIndex;


未经测试,但它应该可以正常工作。






观看和感受:

我认为您可以使用



示例:

 选择选项[禁用] 
{
背景颜色:#FBFBFB;
}

它也可以用于Safari,因为它应该支持CSS。

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.

解决方案

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.

这篇关于是否可以在不禁用组合框选项的情况下取消选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆