我禁用一个按钮,直到至少选中一个复选框,如下所示:
var checkboxes = $("input[type='checkbox']"),
submitButt = $("input[type='button']");
checkboxes.click(function() {
submitButt.attr("disabled", !checkboxes.is(":checked"));
});
我的按钮的初始状态被禁用,但是我需要使其淡出或添加不透明性,我不确定添加类还是仅添加CSS的最佳方法是什么?我不是很确定吗?
如果您要调整禁用按钮的外观,则可以使用CSS属性状态选择器input[type=button][disabled]
:
input[type=button][disabled] {
color: red;
opacity: 0.5;
}
之所以disabled
可行,是因为禁用的按钮具有属性,而启用的按钮没有属性。
例子:
var btn = $("#toggle");
setInterval(function() {
btn.prop("disabled", !btn.prop("disabled"));
}, 1000);
input[type=button][disabled] {
color: red;
opacity: 0.5;
}
<input type="button" value="This is enabled">
<input type="button" disabled value="This is disabled">
<input id="toggle" type="button" value="This one goes back and forth">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句