如何在 jquery 中将下拉菜单设置为只读?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16713436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can i set the drop down as readonly in jquery?
提问by Niths
I want to set the drop down as readonly.
For that I user the code readonly="readonly"
.But its not working in asp.netmvc4.How can I solve this problem?Please help
我想将下拉菜单设置为只读。为此,我使用了代码readonly="readonly"
。但它在 asp.netmvc4 中不起作用。我该如何解决这个问题?请帮忙
回答by Dhaval Marthak
回答by edd
It can be done via jquery. It saves you from browser compatibility issues too. jQuery:
它可以通过jquery完成。它也可以避免浏览器兼容性问题。jQuery:
$('#yourselectid').attr("disabled", true);
回答by johnkavanagh
Unfortunately the select element doesn't accept readonly, W3 spec is here for reference.
不幸的是,select 元素不接受只读,W3 规范在这里供参考。
As others have suggested, your best bet would be to use the disabled 'disabled' attribute instead.
正如其他人所建议的那样,最好的办法是使用禁用的“禁用”属性。