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

Add disabled style (css) to input type file button

本文关键字:样式 css 添加 输入 类型 文件 按钮      更新时间:2023-09-26

我禁用了JQuery中的输入文件按钮

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

但是,按钮看起来仍然是启用的,不显示禁用的样式(灰色)

我试过改变CSS

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

但是不管我放了什么css,按钮都不会改变样式。

我能做什么?

我正在使用的对象(HTML)

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

谢谢

抱歉之前的回答。

我建议你检查这个链接,以了解更改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>

可以用disabled代替true;

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

或者你可以使用。prop()

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

使用prop代替attr:

 $("#id").prop("disabled",true);
https://jsfiddle.net/8fvga3xk/8/

你可以使用CSS选择器:disabledhttp://www.w3schools.com/cssref/sel_disabled.asp

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