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

时间:2016-06-24 09:53:45

标签: javascript jquery css

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

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

但是,按钮仍然显示为启用状态,并且不显示禁用的样式(灰色)

我尝试过更改CSS

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

但无论我把css放在哪个按钮都不会改变风格。

我能做什么?

我正在使用的对象(HTML)

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

由于

3 个答案:

答案 0 :(得分:1)

对不起以前的回答。

我建议您查看有关更改input file样式的this link to know possibility

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>

而不是true,您可以使用disabled;

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

或者您可以使用.prop()

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

答案 1 :(得分:0)

使用prop代替attr:

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

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

答案 2 :(得分:-2)

您可以使用CSS选择器:禁用 http://www.w3schools.com/cssref/sel_disabled.asp

.yourButtonClass:禁用{背景色:#DDDDDD;}

相关问题