复选框输入是否仅选中发布数据? [英] Do checkbox inputs only post data if they're checked?

查看:64
本文介绍了复选框输入是否仅选中发布数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果提交表单时选中了复选框输入值数据,浏览器是否仅发送复选框输入值是标准行为?

Is it standard behaviour for browsers to only send the checkbox input value data if it is checked upon form submission?

如果没有提供值数据,是否

And if no value data is supplied, is the default value always "on"?

假设上述正确,是否在所有浏览器中都一致?

Assuming the above is correct, is this consistent behaviour across all browsers?

推荐答案

是的,标准行为是仅在选中复选框后才发送值。通常,这意味着您需要记住在服务器端期望使用的复选框,因为并非所有数据都从表单返回。

Yes, standard behaviour is the value is only sent if the checkbox is checked. This typically means you need to have a way of remembering what checkboxes you are expecting on the server side since not all the data comes back from the form.

默认值为始终处于开启状态,这在各浏览器之间应保持一致。

The default value is always "on", this should be consistent across browsers.

W3C HTML 4建议中对此进行了介绍


复选框(和单选按钮)是开/关开关,可由用户切换
。设置控制元素的选中
属性时,开关处于打开状态。提交表单后,只有启用复选框
控件才能成功。

Checkboxes (and radio buttons) are on/off switches that may be toggled by the user. A switch is "on" when the control element's checked attribute is set. When a form is submitted, only "on" checkbox controls can become successful.

这篇关于复选框输入是否仅选中发布数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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