POST未经检查的HTML复选框 [英] POST unchecked HTML checkboxes

查看:101
本文介绍了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.

是否有任何方法可以使POST表单被选中不是的复选框,而不是 检查?

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天全站免登陆