如何修复自动激活复选框?

时间:2016-04-18 20:03:02

标签: javascript html web



$(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>
&#13;
&#13;
&#13;

嘿伙计们。我希望我的1元素在复选框处于活动状态时出现,但在网站上加载DOM后立即生效。自动填充=&#34;关闭&#34;属性并没有解决问题。救命!我依靠你们,伙计们!

1 个答案:

答案 0 :(得分:0)

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