php - 标签不与复选框一起使用 - 不保存选中/未选中
问题描述
滑动完美。只要我检查它是否不保存选中/未选中的选项。我知道 ( {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>
{$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>
解决方案
如果您使用复选框,则不应更改该值。复选框的工作方式类似于,如果选中复选框,则提交值,如果未选中复选框,则不提交值。
<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”
推荐阅读
- c++ - 我应该如何为我的 Visual Studio 代码设置编译器?
- terraform - azurerm_resource_group_template_deployment 创建的资源未检测到差异
- python-3.x - 重复序列(优化)
- css - Bootstrap 3 卡水平对齐
- python - 在多个表单中重用 wtforms 字段
- javascript - HTML5视频结束时如何显示div元素
- fluid-framework - 如何连接到 Routerlicious 本地服务器?
- java - Spring:java:包javax.validation.constraints不存在
- javascript - 当我需要 3 个不同的 javascript 时,如何为网址添加逗号?
- python - 使用python使用子进程将不同类型的档案提取到特定文件夹