POST 未选中的 HTML 复选框 [英] POST unchecked HTML checkboxes

查看:26
本文介绍了POST 未选中的 HTML 复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多默认选中的复选框.我的用户可能会取消选中一些(如果有)复选框,而将其余复选框保持选中状态.

I've got a load of checkboxes that are checked by default. My users will probably uncheck a few (if any) of the checkboxes and leave the rest checked.

有什么办法可以让表单发布选中的复选框,而不是选中的复选框?

Is there any way to make the form POST the checkboxes that are not checked, rather than the ones that are checked?

推荐答案

为具有不同 ID 的复选框添加隐藏输入:

Add a hidden input for the checkbox with a different ID:

<input id='testName' type='checkbox' value='Yes' name='testName'>
<input id='testNameHidden' type='hidden' value='No' name='testName'>

提交表单前,根据勾选的条件禁用隐藏输入:

Before submitting the form, disable the hidden input based on the checked condition:

if(document.getElementById("testName").checked) {
    document.getElementById('testNameHidden').disabled = true;
}

这篇关于POST 未选中的 HTML 复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆