在IE-8和FF-3.5.8中设置readonly属性的jQuery不一致 [英] jQuery inconsistency in setting readonly attribute in IE-8 and FF-3.5.8
问题描述
var $ inputs = mySelectors();
$ inputs.each(function(){
$(this).attr(readonly,true);
});
此代码适用于IE8,但不适用于FF3.5
IE输出(如IE Developer工具栏所示)< input type =textreadOnly =readonly.... />
FF输出(用Firebug看) 什么是正确的方法来设置它? 或 或 看起来像有一个旧的错误,但不知道它是否得到解决。 参考: http://api.jquery.com/attr/ 跨浏览器一致性:一些 是否有解决跨浏览器不一致问题的方法?如果它是我的代码,我可能会设置它为纯布尔真: 当你说这不起作用;究竟发生了什么? 下面是一个示例脚本: http: //gutfullofbeer.net/readonly.html 这个使用了我上面的方法,对我来说在Firefox中工作得很好。 Firebug显示这样的属性,因为它的感觉。 This is my code inside document.ready: This code works for IE8, but not for FF3.5 IE output(as seen with IE Developer toolbar) FF output (seen with Firebug)
What is the right way to set it ? or or Looks like there was an old bug but not sure if it got resolved.
http://osdir.com/ml/jquery-dev/2009-05/msg00115.html reference:http://api.jquery.com/attr/ Cross-browser consistency: Some
attributes have inconsistent naming
from browser to browser. Furthermore,
the values of some attributes are
reported inconsistently across
browsers, and even across versions of
a single browser. The .attr() method
reduces such inconsistencies. IS there a way to tackle this cross browser inconsistency ? If it were my code, I'd probably set it to plain boolean "true": When you say that it doesn't work; what exactly happens? Here's a sample script: http://gutfullofbeer.net/readonly.html That one uses my method above, and it works just fine in Firefox for me. Firebug shows the attribute like that because it feels like it. 这篇关于在IE-8和FF-3.5.8中设置readonly属性的jQuery不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
< input type =textreadonly => $ c $
$ elem.attr( 只读, 真);
$ elem.attr( 只读, 只读);
$ elem.attr( readOnly的, 只读); //注意只有
中的大写字母O
http://osdir.com/ml/jquery- dev / 2009-05 / msg00115.html
属性从浏览器到浏览器命名
不一致。此外,
的某些属性的值是
在
浏览器中不一致的报告,甚至在单个浏览器的
版本中也是如此。 .attr()方法
减少了这种不一致性。
$ elem.attr('readOnly',true);
var $inputs = mySelectors();
$inputs.each(function() {
$(this).attr("readonly", "true");
});
<input type="text" readOnly="readonly"..../>
<input type="text" readonly="">
$elem.attr("readonly","true");
$elem.attr("readonly","readonly");
$elem.attr("readOnly","readonly"); //note the uppercase O in Only
$elem.attr('readOnly', true);