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

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

问题描述

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

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

如果没有提供值数据,默认值总是on"吗?

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.

默认值总是on",这在浏览器之间应该是一致的.

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