我有一个提交按钮,它的颜色红色css风格在默认情况下。如何在不使用jquery刷新页面的情况下动态应用css样式并查看结果?
我有一个oncheck查询,我想把代码,将改变样式以上的返回真;
我的纽扣
<input type="submit" name="submit" id="submitForm" class="btn btn-primary-alt" value="Submit" onsubmit="return validate_age();" />我想在提交按钮上应用的css样式
.btn-primary-alt:hover {
background-color: #3b8410;
border-bottom: 3px solid #2a620a;
border-color: #2a620a;
color: #fff;
}我的jquery
if($("#age_18").is(":checked"))
{
// This is where I want the css styling will happen.
return true;
}
else
{
alert("You must be above 18 years of age.");
return false;
}因此,基本上,当选中复选框时,我希望在提交按钮上添加css样式。谢谢
发布于 2015-06-01 12:21:46
最好的解决方案是创建一个新的类(不是:悬停)。所以,例如
.checked{
background-color: #3b8410;
border-bottom: 3px solid #2a620a;
border-color: #2a620a;
color: #fff;
}然后使用jQuery添加或删除类。
$('#submitForm').addClass('checked');和
$('#submitForm').removeClass('checked');发布于 2015-06-01 12:20:15
您可以这样声明您的css
.btn-primary-alt-hover,.btn-primary-alt:hover {
background-color: #3b8410;
border-bottom: 3px solid #2a620a;
border-color: #2a620a;
color: #fff;
}然后你可以像这样把这个应用在你的按钮上
$("#submitForm").addClass('btn-primary-alt-hover');发布于 2015-06-01 12:20:09
$("#age_18").change(function(){
if($("#age_18").is(":checked")) {
// Add Your Styling Here to Submit Button...
return true;
} else {
alert("You must be above 18 years of age.");
return false;
}
})你的逻辑是完美的只有一件事。
您必须调用它的Change函数来检查复选框是否选中。
https://stackoverflow.com/questions/30573264
复制相似问题