首页 > 解决方案 > 标签不与复选框一起使用 - 不保存选中/未选中

问题描述

滑动完美。只要我检查它是否不保存选中/未选中的选项。我知道 ( {if isset($tmp.negotiable) && $tmp.negotiable==1}checked="checked"{/if} ) 有问题。

<div class="switch-box col-xs-6 col-sm-2 col-md-2 col-lg-2 no-hor-padding" style="width:50%;">
    <div class="switch-1 col-xs-12 col-sm-12 col-md-12 col-lg-12 no-hor-padding">
        {if $pe_settings[$fieldset].use_negotiable==1}
            <input type="checkbox" class="cmn-toggle-1 cmn-toggle-round-1" name="negotiable" id="negotiable" {if isset($tmp.negotiable) && $tmp.negotiable==1}checked="checked"{/if} value="0" />
            <label for="negotiable"></label>
&nbsp;&nbsp;{$pe_settings[$fieldset].lang[$crt_lang].negotiable}
        {/if}
    </div>
</div>

如果我删除

> <label for="negotiable"></label>

它可以工作并保存选项。

JavaScript:

<script>
    {literal}

$(document).ready(function() {

    $("#negotiable").click(function() {
    if( $(this).attr('checked') ){
        $("#negotiable").val('0');
        $('#negotiable').removeAttr('checked');
    }else{
        $("#negotiable").val('1');
        $('#negotiable').attr('checked','checked');
    }
    });

});
{/literal}
</script>

标签: phphtmlcsssmarty

解决方案


如果您使用复选框,则不应更改该值。复选框的工作方式类似于,如果选中复选框,则提交值,如果未选中复选框,则不提交值。

<input type="checkbox" class="cmn-toggle-1 cmn-toggle-round-1" name="negotiable" id="negotiable" {if isset($tmp.negotiable) && $tmp.negotiable==1}checked="checked"{/if} value="1" />

基本上,您应该将复选框的值设置为“1”


推荐阅读