是否可以在不禁用组合框选项的情况下取消选择? [英] Is it possible to make Combo box option unselectable without disabling it?
问题描述
可能存在重复:
禁用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屋!