是否< input type =" checkbox" />只有发布数据,如果它被选中?

问题描述:

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

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.

默认值是始终打开,这应该是跨浏览器一致。

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

这包含在 W3C HTML 4建议中


复选框(和单选按钮)是开关,用户可以切换
。当控制元素的选中
属性被设置时,开关是on。提交表单时,只有on复选框
控件可以成功。

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.