问题描述
这是我在document.ready中的代码: var $ inputs = mySelectors();
$ inputs.each(function(){
$(this).attr(readonly,true);
});
此代码适用于IE8,但不适用于FF3.5
IE输出(如IE Developer工具栏所示)< input type =textreadOnly =readonly.... />
FF输出(用Firebug看) 什么是正确的方法来设置它? 或 或 看起来像有一个旧的错误,但不知道它是否得到解决。 参考: 是否有解决跨浏览器不一致问题的方法?如果它是我的代码,我可能会设置它为纯布尔真: 当你说这不起作用;究竟发生了什么? 下面是一个示例脚本: 这个使用了我上面的方法,对我来说在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/ 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不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
< input type =textreadonly => $ c $
$ elem.attr( 只读, 真);
$ elem.attr( 只读, 只读);
$ elem.attr( readOnly的, 只读); //注意只有
中的大写字母O
$ 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);