<input id="test" type="text" value="text" />
alert($(':input:not([readonly])').length); // 1
$('#test').attr('readonly', 'readonly');
alert($(':input:not([readonly])').length); // 1
$('#test').removeAttr('readonly');
alert($(':input:not([readonly])').length); // 1
继the question here,我不能得到解决工作,因为它似乎jQuery的不正确设置只读属性(或者至少一致)。jQuery的设定只读读ATTR在文本框
注意我会得到相同的结果与$('#test').attr('readonly', true);
我使用的是Chrome和只读属性呈现为readonly=""
。这里有另一篇文章,这表明FireFox也是如此。
我对此没有太多打扰,尽管它仍然停止了文本框的编辑,但是我无法找到一种方法来检测只读属性。
我通常喜欢jQuery,但这都是有点WTF。
任何想法?
您看到此行为的原因是因为'[readonly]'选择器只是检查属性的*存在*,而'true'或'false',所以它存在。 – 2010-09-14 15:12:14