下拉菜单中的"jQuery禁用"选项 [英] Jquery Disable option in dropdown
本文介绍了下拉菜单中的"jQuery禁用"选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们,我使用以下代码禁用了使用jQuery的选项( jquery-1.4.2.min ).该禁用发生在Firefox中,但没有出现在IE中.
Guys i have used the following code to disable an option using jQuery (jquery-1.4.2.min).The disable happens in Firefox , but not in IE.
<SELECT NAME="SCOPE" id="SCOPE">
<OPTION VALUE="G"> Global
<OPTION VALUE="D"> Dynamic
</SELECT>
$("#SCOPE option[value='G']").attr("disabled","disabled");
$("#SCOPE option[value='D']").attr("selected", "selected");
推荐答案
我认为我可能是错的,但这可能是因为可以禁用选择而不是选择.由于firefox很棒,而且IE很烂,所以您可以猜出为什么:)您遇到了这个问题.使用CSS将该选项的文本显示为灰色.
I think i might be wrong but it could be because the select rather than option can be disabled. Since firefox is great and IE sucks, well you can guess why :) you having that problem. Use css to grey out the text of that option.
然后在jquery上执行类似的操作.
then on jquery do something like this.
$('#SCOPE').change(function(){
if($('#SCOPE option[value="'+$(this).val()+'"]').attr('disabled') == 'disabled'){
alert('Its disabled you cannot select this option');
}
});
顺便说一句.请仔细检查代码,因为我尚未对此进行测试:)
BTW. double check the code as I have not tested this :)
这篇关于下拉菜单中的"jQuery禁用"选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文