jQuery .attr('disabled', 'disabled') 或 .attr('disabled', true) 用于禁用输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24947105/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 02:42:17  来源:igfitidea点击:

.attr('disabled', 'disabled') or .attr('disabled', true) for disabling input

jquery

提问by pistachioesque

Both .attr('disabled', 'disabled')and .attr('disabled', true)work in my code, but I'm just wondering: which among the two is more efficient and/or which is more used? Is there really a difference? Performance-wise, maybe?

双方.attr('disabled', 'disabled').attr('disabled', true)在我的代码工作,但我只是想知道:这两个之间是更有效和/或更使用?真的有区别吗?性能方面,也许?

回答by rjpedrosa

Should not make any difference. But from jQuery1.6+ you should use $("input").prop('disabled', true);

应该没有任何区别。但是从 jQuery1.6+ 你应该使用$("input").prop('disabled', true);