复选框选中复选框背景颜色并取消选中 [英] Change checkbox background color on checkbox check and uncheck
本文介绍了复选框选中复选框背景颜色并取消选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在gridview中有一个复选框,我想在检查时取消背景颜色并取消选中。
I have a checkbox inside a gridview of which I want to change the backcolor on check and uncheck.
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:CheckBox ID="checkboxAttendanceStatus" ClientIDMode="Static" BackColor="red" runat="server" />
</ItemTemplate>
</asp:TemplateField>
我为此目的使用了一个jquery,但是它没有用。
I used a jquery for the purpose but it's not working.
<script>
$(document).ready(function () {
$('#checkboxAttendanceStatus').change(function () {
alert('asdas');
$("#checkboxAttendanceStatus").css("backcolor", "green");
});
});
</script>
推荐答案
检查小提琴
HTML(示例):
<div id="div">
<input type="checkbox" id="chk">
</div>
JS:
$('#chk').on('change', function(){
if($('#chk').prop('checked'))
$('#div').css('background', 'green');
else
$('#div').css('background', 'red');
});
这篇关于复选框选中复选框背景颜色并取消选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文