gpt4 book ai didi

html - 根据 slider (复选框)选择显示/隐藏 div

转载 作者:行者123 更新时间:2023-11-28 01:33:52 24 4
gpt4 key购买 nike

有没有办法根据 slider 的位置来显示/隐藏 hiddencar div?我不确定如何使用 :target 选择器,我相信它可以单独使用 css 来完成

是显示div 没有隐藏div

	    .onoffswitch4 {
position: relative; width: 101px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox4 {
display: none;
}
.onoffswitch-label4 {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid ; border-radius: 11px;
}
.onoffswitch-inner4 {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner4:before, .onoffswitch-inner4:after {
display: block; float: left; width: 50%; height: 38px; padding: 0; line-height: 38px;
font-size: 13px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner4:before {
content: "No";
padding-left: 14px;
background-color: #34A7C1; color: #FFFFFF;
}
.onoffswitch-inner4:after {
content: "Yes";
padding-right: 14px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch4 {
display: block; width: 9px; margin: 14.5px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 59px;
border: 2px solid ; border-radius: 11px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox4:checked + .onoffswitch-label4 .onoffswitch-inner4 {
margin-left: 0;
}
.onoffswitch-checkbox4:checked + .onoffswitch-label4 .onoffswitch-switch4 {
right: 0px;
}
   <div id="contact_phone">Do you have a car?: *<br>
<div class="onoffswitch4">
<input type="checkbox" name="onoffswitch4" class="onoffswitch-checkbox4" id="myonoffswitch4" checked>
<label class="onoffswitch-label4" for="myonoffswitch4">
<span class="onoffswitch-inner4"></span>
<span class="onoffswitch-switch4"></span>
</label>
</div>


<div id="hiddencar">

<div id="contact_name">Year: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/>
</div>


<div id="contact_phone">Make: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/>
</div>


<div id="contact_phone">Model: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/>
</div>

</div><!--hiddencar-->



</div><!--contact_phone-->

有没有办法根据 slider 的位置来显示/隐藏 hiddencar div?我不确定如何使用 :target 选择器,我相信它可以单独使用 css 来完成

是显示div 没有隐藏div

最佳答案

出于某种原因,CSS slider 实际上并没有改变复选框的选中属性,我在我的 JS 解决方案中添加了这个以及一个 showHideCarFields 函数,该函数将根据需要显示或隐藏汽车字段

$(document).ready(function() {
$(document).on("click", ".onoffswitch4", function() {
$("#myonoffswitch4").prop("checked", !$("#myonoffswitch4").prop("checked"))
showHideCarFields();
});
showHideCarFields();
});

function showHideCarFields() {
var isChecked = $('#myonoffswitch4').prop("checked");
if(isChecked) {
$('#hiddencar').hide();
} else {
$('#hiddencar').show();
}
}
.onoffswitch4 {
position: relative; width: 101px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox4 {
display: none;
}
.onoffswitch-label4 {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid ; border-radius: 11px;
}
.onoffswitch-inner4 {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner4:before, .onoffswitch-inner4:after {
display: block; float: left; width: 50%; height: 38px; padding: 0; line-height: 38px;
font-size: 13px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner4:before {
content: "No";
padding-left: 14px;
background-color: #34A7C1; color: #FFFFFF;
}
.onoffswitch-inner4:after {
content: "Yes";
padding-right: 14px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch4 {
display: block; width: 9px; margin: 14.5px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 59px;
border: 2px solid ; border-radius: 11px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox4:checked + .onoffswitch-label4 .onoffswitch-inner4 {
margin-left: 0;
}
.onoffswitch-checkbox4:checked + .onoffswitch-label4 .onoffswitch-switch4 {
right: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="contact_phone">Do you have a car?: *<br>
<div class="onoffswitch4">
<input type="checkbox" name="onoffswitch4" class="onoffswitch-checkbox4" id="myonoffswitch4" checked>
<label class="onoffswitch-label4" for="myonoffswitch4">
<span class="onoffswitch-inner4"></span>
<span class="onoffswitch-switch4"></span>
</label>
</div>


<div id="hiddencar">

<div id="contact_name">Year: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/>
</div>


<div id="contact_phone">Make: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/>
</div>


<div id="contact_phone">Model: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/>
</div>

</div><!--hiddencar-->



</div><!--contact_phone-->

关于html - 根据 slider (复选框)选择显示/隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50801401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com