简体   繁体   English

将禁用样式(css)添加到输入类型文件按钮

[英]Add disabled style (css) to input type file button

I am disabling a input file button in JQuery which works我正在禁用 JQuery 中的输入文件按钮

$('#ID').attr('disabled', true)

However, the button still looks enabled and doesn't show the disabled style (grey)但是,按钮看起来仍然启用并且不显示禁用样式(灰色)

I have tried changing the CSS我试过改变 CSS

// Example 
$('#ID').css("background-color", 'yellow')

But regardless of what css I put the button never changes style.但是无论我放什么 css,按钮都不会改变样式。

What I can do?我能做什么?

the object I am using (HTML)我正在使用的对象(HTML)

<input type="file" id="ID" class="" name="files[]" multiple />

Thanks谢谢

Use prop instead attr:使用 prop 代替 attr:

 $("#id").prop("disabled",true);

https://jsfiddle.net/8fvga3xk/8/ https://jsfiddle.net/8fvga3xk/8/

Sorry for previous answer.抱歉之前的回答。

I suggest you to check this link to know possibility about changing a input file style.我建议您查看此链接以了解更改input file样式的可能性

 div.fileinputs { position: relative; } div.fakefile { position: absolute; top: 0px; left: 0px; z-index: 1; } input.file { position: relative; text-align: right; -moz-opacity:0 ; filter:alpha(opacity: 0); opacity: 0; z-index: 2; }
 <div class="fileinputs"> <input type="file" class="file" disabled/> <div class="fakefile"> <input disabled/> <img src="http://fptp.uthm.edu.my/mba/images/911c660826c0b.png" style="width:30px;"/> </div> </div>

instead of true you can use disabled ;您可以使用disabled代替 true ;

$("#ID").attr('disabled','disabled');

or you can use .prop()或者你可以使用.prop()

$("#ID").prop('disabled', true);
$("#ID").prop('disabled', false);

You can use the CSS selector :disabled http://www.w3schools.com/cssref/sel_disabled.asp您可以使用 CSS 选择器:禁用http://www.w3schools.com/cssref/sel_disabled.asp

.yourButtonClass:disabled{
   background-color:#dddddd;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM