设置为“off”时,CSS 3复选框值为null

时间:2013-12-04 05:04:20

标签: html css

我有以下复选框:

<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/

生成的代码

1 个答案:

答案 0 :(得分:0)

在复选框前面添加一个名称相同的隐藏字段,其值为“OFF”