<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