jQuery disabled 属性在 firefox 中不起作用 - 对于 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6074529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
disabled attribute does not work in firefox - for a div
提问by SilverLight
hi my dear friends :
the below code works perfect in ie9 , but does not work in firefox 3.6
嗨,亲爱的朋友们:
以下代码在 ie9 中运行良好,但在 Firefox 3.6 中不起作用
$('#ctl00_ContentPlaceHolder1_RadUploadImage').attr('disabled', 'disabled');
ctl00_ContentPlaceHolder1_RadUploadImage -> is a div element
ctl00_ContentPlaceHolder1_RadUploadImage -> 是一个 div 元素
mean when we check this div with firebug , shows us disabled="disabled"
but i have a RadUpload Inside that div that is working still!
意思是当我们用 firebug 检查这个 div 时,向我们显示 disabled="disabled"
但我在那个 div 中有一个 RadUpload 仍在工作!
the html code is like below :
html代码如下:
<div disabled="true" id="ctl00_ContentPlaceHolder1_RadUploadImage" class="RadUpload RadUpload_BlackByMe RadUpload_rtl RadUpload_BlackByMe_rtl" style="width: 325px;">
<input autocomplete="off" id="ctl00_ContentPlaceHolder1_RadUploadImage_ClientState" name="ctl00_ContentPlaceHolder1_RadUploadImage_ClientState" type="hidden">
<ul class="ruInputs" id="ctl00_ContentPlaceHolder1_RadUploadImageListContainer"><li><span class="ruFileWrap ruStyled"><input style="position: absolute; left: 0px; top: -5000px;" class="ruFileInput" size="23" dir="ltr" id="ctl00_ContentPlaceHolder1_RadUploadImagefile0" name="ctl00_ContentPlaceHolder1_RadUploadImagefile0" type="file"><input size="22" class="ruFakeInput" type="text"><input class="ruButton ruBrowse" value="select" type="button"></span><input name="ClearInput" class="ruButton ruClear" value="erase" id="ctl00_ContentPlaceHolder1_RadUploadImageclear0" type="button"></li></ul></div>
any idea?
任何的想法?
thanks in advance
提前致谢
回答by Naftali aka Neal
if you are using jQuery < 1.6 do this:
如果您使用的是 jQuery < 1.6,请执行以下操作:
$('#ctl00_ContentPlaceHolder1_RadUploadImage').attr("disabled", 'disabled');
If you are using jQuery 1.6+:
如果您使用的是 jQuery 1.6+:
$('#ctl00_ContentPlaceHolder1_RadUploadImage').prop("disabled", true);
See this question: .prop() vs .attr()for references why.
请参阅此问题:.prop() vs .attr()以了解原因。
Same answer was given here: jQuery .attr("disabled", "disabled") not working in Chrome
这里给出了相同的答案:jQuery .attr("disabled", "disabled") not working in Chrome
回答by Asem Khatib
You don't have to use JQ for that , just use pure JS like that :
您不必为此使用 JQ,只需使用纯 JS 即可:
document.getElementById('x').disabled = true;
or if you wanna UNdisable it :
或者如果你想取消禁用它:
document.getElementById('x').disabled = false;
回答by Satish
This is discussed here too: http://forum.jquery.com/topic/disable-image-button