【发布时间】:2017-10-18 02:05:15
【问题描述】:
我已经坚持了一段时间了。为了快速解释,我有一张不同复选框的表格。用户选中许多框并继续单击。同一个表格显示在另一个页面上/被选中的框应该通过单击按钮来加载。
我的问题是,如何通过单击按钮将样式复选框的颜色更改为另一种颜色。
更新,我已经添加了代码,很抱歉造成混乱,第一次使用这个
table.example1, table.example1 th, table.example1 td {
border: 3px solid grey;
max-width: 200px;
}
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label {
display:inline-block;
padding: 6px 60px;
margin-bottom: 0;
font-size: 14px;
line-height: 20px;
color: white;
text-align: center;
vertical-align: middle;
cursor: pointer;
background-color: transparent;
background-repeat: repeat-x;
}
input[type=checkbox]:checked + label{
background-color: #3e618b;
outline: 0;
}
<table class="example1" id="example" style="width:40%;" align='center'>
<tr>
<td>
<input type="checkbox" id="chk1" name="chk" value="1">
<label for="chk1"> 1</label>
</td>
<td>
<input type="checkbox" id="chk2" name="chk"value="2">
<label for="chk2"> 2</label>
</td>
</tr>
</table>
<button>Changes checked checkbox color</button>
【问题讨论】:
-
显示复选框的 html。
-
在单击按钮时,您可以使用 jquery 添加到所有选定的复选框中,您可以使用 css 自定义(设置您想要的颜色)另一个类...如果您想要一个可行的解决方案,但是您应该提供您的 html。
-
欢迎来到 StackOverflow.com。请在您的问题中添加一些代码。您可以使用jsfiddle.net 重现您的代码问题。
-
请添加一些代码
-
并非所有浏览器甚至都支持复选框样式或支持相同程度的样式。
标签: javascript jquery html css checkbox