使用jquery 1.6 .prop()将控件设置为只读 [英] Setting a control to readonly using jquery 1.6 .prop()

查看:275
本文介绍了使用jquery 1.6 .prop()将控件设置为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着jQuery 1.6的发布,关于SO的建议通常是开始使用您以前使用attr()的prop().

With the release of jQuery 1.6, the recommendation on SO has been to generally start using prop() where you used to use attr().

当我想将一个元素设置为只读时会发生什么?

What happens when I want make an element readonly?

$('.control').prop('readonly', 'readonly');
$('.control').prop('readonly', true);

这些似乎都不使控件变为只读.将元素设为只读是规则的例外吗?

Neither of these seem to make the control readonly. Is making an element readonly the exception to the rule?

推荐答案

问题是属性名称区分大小写.试试:

The problem is that the property name is case-sensitive. Try:

$('.control').prop('readOnly', true);

尽管我真的不知道为什么这需要jQuery.效果也一样:

Though really I don't know why this requires jQuery. This works just as well:

document.getElementsByClassName("control")[0].readOnly = true;

这篇关于使用jquery 1.6 .prop()将控件设置为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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