저는 CSS와 jquery를 사용하여 기본적인 맞춤 체크 박스를 만들려고합니다. 이 코드는 다음과 같습니다.맞춤 체크 박스 만들기
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
<style>
input[type="checkbox"]{
/*display:none;*/
}
.label .checkbox{
width:25px;
height:25px;
background-color:rgba(0,0,0,0.6);
border-radius:15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
position:absolute;
z-index:1000;
padding:2px 3px 0 0;
}
.label .checkbox .circle{
display:none;
background-color:#af213c;
line-height:25px;
text-align:center;
z-index:0;
border-radius:600px;
-moz-border-radius:600px;
-webkit-border-radius:600px;
height:23px;
width:23px;
}
.label{
padding-right:34px;
line-height: 30px;
font-family: "b yekan";
}
.label:hover{
text-decoration:underline;
}
.labelcheck{
color:#af213c;
}
.labelcheck .checkbox .circle{
display:block;
}
.labelcheck .checkbox{
z-index:0;
}
</style>
</head>
<body>
<label id="new" for="remember">remember me:</label>
<input type="checkbox" name="data[remember]" id="remember" value="1">
<script>
$('input[type="checkbox"][id="remember"]').prev('label').append("<div class='checkbox'><div class='circle'></div></div>");
$('input[type="checkbox"][id="remember"]').prev('label').addClass('label');
var $chbx = $('input[type="checkbox"][id="remember"]')
$chbx.onchange=function() {
var label = $('label[for="'+$(this).attr('id')+'"]');
if(this.checked=true) {
label.addClass('labelcheck');
}
else if (this.checked=false){
label.addClass('label');
}
};
</script>
</body>
</html>
복사하여보십시오. 나는 체크 박스의 각 상태를 스타일링 할 수 있도록 라벨의 클래스를 변경하고 싶다. 그래서 나는 라벨 클래스를 체크 박스 상태와 연관시키기 위해 onchange를 사용했다. 레이블의 클래스는 변경되지 않습니다. 그러나 다른 문제가있을 수 있지만, 나는 그것을 깨닫지 못합니다. 이 같은
당신이 (www.jsfiddle.net) – tymeJV
'경우 (this.checked = TRUE) {''해야하는 경우 (this.checked === 사실) {바이올린을 만들 수 working jsFiddle here보기 'else if (this.checked = false) {'를'else {'로 변경하십시오. –
... http://jshint.com과 같은 도구를 사용하여 간단하고 일반적인 실수를 찾습니다. 이것은 묻기 전에 일어나는 기본적인 디버깅의 일부입니다. –