这里是小提琴。我正在尝试通过使用<div>
和应用颜色来制作自己的复选框$().css()
。当您单击 时div
,我试图$().toggleClass()
在单击功能中使用将背景颜色更改为#96f226
jQuery:
$('div').mouseenter(function(){
$(this).css('background','#656565');
});
$('div').mouseleave(function(){
$(this).css('background','#4a4a4a');
});
$('div').click(function(){
$(this).toggleClass('active');
});
HTML:
<div></div>
CSS:
div {
width: 15px;
height: 15px;
background: #4a4a4a;
cursor: pointer;
}
.active {
background: #96f226
}