如何修复自动激活复选框

How to fix auto activating checkbox?

本文关键字:激活 复选框 何修复      更新时间:2023-09-26

$(document).ready(function(){
		if($('.checkbox1').attr('checked') == true) {
			$(".worddoc").animate({opacity:1},700);
		}
	})
.checkbox1 {
  width: 50px;
  height: 26px;
  position: absolute;
  display: none;
}
.checkbox1:not(checked) + label {
  padding-right: 100%;
  position: relative;
}
.checkbox1:not(checked) + label:after {
  content: '';
  position: absolute;
  top: -4px;
  left: 71%;
  width: 50px;
  height: 26px;
  border-radius: 13px;
  background: #CDD1DA;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  float: right;
}
.checkbox1:not(checked) + label:not(checked):before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 10px;
  background: #FFF;
  left: 73%;
  top: -2px;
  z-index: 998;
  transition: all 0.2s;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  -o-transition: all 0.2s;
  -ms-transition: all 0.2s;
  cursor: pointer;
  float: right;
}
.checkbox1:checked + label:after {
  background: #9FD468;
}
.checkbox1:checked + label:before {
  left: 82%;
}
.label1 {
  color: white;
  font-family: OpenSansRegular;
  font-size: 15px;
  position: absolute;
  float: left;
  top: 30px;
  margin-left: 0;
}
.worddoc {
  width: 40px;
  height: 40px;
  background: orange;
  z-index: 999;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="checkbox" class="checkbox1" id="checkbox1" autocomplete="off"/>
		<label for="checkbox1" class="label1">jQuery</label>
<div class="worddoc"></div>

嘿,伙计们。我希望我的1元素在复选框处于活动状态时出现,但在网站上加载DOM后它会立即变为活动状态。autocomplete="off"属性不能解决问题。救命!我依靠你们,伙计们!

$(document).ready(function(){
    $('.checkbox1').click(function () {
        if($(this).attr('checked')) {
        $(".worddoc").animate({opacity:1,right:0},700);
    }
    });
});