gpt4 book ai didi

html - 当设置为 "off"时,CSS 3 复选框值为空

转载 作者:行者123 更新时间:2023-11-28 11:49:25 25 4
gpt4 key购买 nike

我有以下复选框:

<div class="onoffswitch">
<input type="checkbox" name="showOnNavigation" class="onoffswitch-checkbox" id="showOnNavigation" checked>
<label class="onoffswitch-label" for="showOnNavigation">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>

它的 CSS:

.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}

.onoffswitch-checkbox {
display: none;
}

.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}

.onoffswitch-inner {
width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}

.onoffswitch-inner:before, .onoffswitch-inner:after {
float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}

.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #A3D900; color: #FFFFFF;
}

.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #CCCCCC; color: #333333;
text-align: right;
}

.onoffswitch-switch {
width: 25px; margin: 2.5px;
background: #000000;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 56px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}

当我提交表单并且复选框位于 ON 位置时,复选框值为 ON。当它处于 OFF 位置时,该值未设置为 OFF,因此我的脚本将发出未设置索引的错误。它曾经工作过,但由于某种原因它不再工作了。真的很郁闷,求助!!仅 CSS 的方法是最受青睐的,否则我可以使用 JavaScript 轻松地做到这一点。

我得到了从 http://proto.io/freebies/onoff/ 生成的代码

最佳答案

在您的复选框前放置一个同名的隐藏字段,其值为“OFF”

关于html - 当设置为 "off"时,CSS 3 复选框值为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20367261/

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