Javascript 选中复选框时使用jquery更改样式表
我有这个密码Javascript 选中复选框时使用jquery更改样式表,javascript,jquery,css,Javascript,Jquery,Css,我有这个密码 <form action="creatPro.php"> <input type="checkbox" name="okk" value="agree" id="okk" onClick="EnableSubmit (this)" />agree <br /> <center> <input type="submit" name="startthis" value="agree" dis
<form action="creatPro.php">
<input type="checkbox" name="okk" value="agree" id="okk" onClick="EnableSubmit (this)" />agree
<br />
<center>
<input type="submit" name="startthis" value="agree" disabled id="startthis" class="styled-button-8" />
</center>
</fieldset>
</form>
选中复选框时,应执行以下操作:
- 启用按钮
submit
- 例如,将按钮颜色更改为蓝色
启用时,如何使用Jquery
更改按钮颜色
这就是我所尝试的
$(document).ready(function(){
$("input[type=checkbox]").checked(function(){
$("input[type=submit]").css({"background-color":"blue"});
});
});
()
或
$("#startthis").css( "background-color", "blue" );
使用jQuery,您可以执行以下操作:
$('#okk').change(function () {
if ($(this).is(':checked')) {
$('#startthis').css('background-color','blue').prop('disabled', false);
} else {
$('#startthis').css('background-color','#ccc').prop('disabled', true);
}
});
您尚未将jQuery
添加到fiddle
中,将其作为库添加到fiddle
中,并将以下行添加到启用提交
功能中:
$('#startthis').css('background-color', 'blue');
您可以在css中简单地使用:checked选择器来实现此紫色
#startthis:checked{background-color:blue;}
#startthis{background-color:white;}
是的,我试过了,现在就发布抱歉^^注意更改“color”属性将更改按钮文本的颜色,而更改“background color”属性将更改按钮的颜色。谢谢您的帮助^^
$('#startthis').css('background-color', 'blue');
#startthis:checked{background-color:blue;}
#startthis{background-color:white;}