是否有一个标准的客户端行为来提交一个空的选择多个?[英] Is there a standard client behaviour for submitting an empty select multiple?

本文是小编为大家收集整理的关于是否有一个标准的客户端行为来提交一个空的选择多个?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

http://www.w.w.w3.org/tr/html401/互动/forms.html#edef-select

如果提交的选择多个为空,则未指定客户端应如何行为.有人知道是否有标准?

推荐答案

可悲的是,我没有时间对此进行测试,但我希望以下能力可以帮助您...

如果我没错,则默认情况下,当页面加载时,将选择第一个元素.因此,使用具有multiple属性的Active和一些options的form和a select创建一个非常简单的HTML文件.然后,打开文件以查看一些浏览器中发生的情况,例如Chrome,Firefox,Internet Explorer,Opera和Safari.

另一件事是在这里查看html5对此的看法: http://dev.w3.org/html5/spec/overview.html#the-select-element .

更新

W3C HTML 4.01标准指出此(在您提供的链接中滚动一点):

17.6.1预选的选项

零或更多选择可能是 预先选择用户.用户代理 应该确定哪些选择是 预选如下:

如果没有选项元素具有选定的 属性集,用户代理行为 选择哪个选项最初是 选择的是不确定的.笔记.自从 现有的实现处理此操作 情况不同,电流 规格与RFC 1866不同 ([RFC1866]第8.1.3节), 状态:初始状态具有 选择的第一个选项,除非 任何选定的属性都存在于任何 元素. 因为用户 代理行为有所不同,作者应该 确保每个菜单都包含一个 默认预选选项.

如果一个选项元素已选择 属性集,应该是 预选.如果选择元素 具有多个属性集和 多个选项元素具有 选定的属性集,他们应该 全部都是预选的.已经被考虑了 如果多个选项,则错误 元素具有所选属性集 并且选择元素没有 多个属性集.用户 代理商的处理方式可能有所不同 此错误,但不应预选 多个选择.

其他推荐答案

不幸的是,@Alerty错误.如果选择元素上存在多个属性,但没有选项元素具有所选属性,则默认情况下 no 元素. (在Win 7上在IE 9,FF 5,Chrome 13和Safari 5上进行测试.)

那么,如果用户不选择任何内容尚未提交表单,Web浏览器该怎么办?它应该完全按照您的期望:不提交选择.这正是当前版本的HTML5规范所说的:

"多个属性是一个布尔属性.如果存在属性,则选择元素代表从选项列表中选择 Zero 或更多选项的控件."

."

http://dev.w3.org/html5/spec/overview.html#select-element

本文地址:https://www.itbaoku.cn/post/1834074.html

问题描述

http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT

Doesn't specify how the client should behave if the submitted select multiple is empty. Does anyone know whether there is a standard for that ?

推荐答案

Sadly, I do not have the time to test this, but I hope the following can help you...

If I am not mistaken, the first element is selected by default when the page is loaded. Therefore, create a very simple HTML file with a form and a select that has the multiple attribute active and with a few options. Then, open the file to see what happens in a few browsers such as Chrome, Firefox, Internet Explorer, Opera and Safari.

Another thing would be to look what HTML5 says about this here: http://dev.w3.org/html5/spec/Overview.html#the-select-element.

UPDATE

The W3C HTML 4.01 standard states this (scroll a bit down in the link you provided):

17.6.1 Pre-selected options

Zero or more choices may be pre-selected for the user. User agents should determine which choices are pre-selected as follows:

If no OPTION element has the selected attribute set, user agent behavior for choosing which option is initially selected is undefined. Note. Since existing implementations handle this case differently, the current specification differs from RFC 1866 ([RFC1866] section 8.1.3), which states: The initial state has the first option selected, unless a SELECTED attribute is present on any of the elements. Since user agent behavior differs, authors should ensure that each menu includes a default pre-selected OPTION.

If one OPTION element has the selected attribute set, it should be pre-selected. If the SELECT element has the multiple attribute set and more than one OPTION element has the selected attribute set, they should all be pre-selected. It is considered an error if more than one OPTION element has the selected attribute set and the SELECT element does not have the multiple attribute set. User agents may vary in how they handle this error, but should not pre-select more than one choice.

其他推荐答案

Unfortunately, @Alerty is mistaken. If the multiple attribute is present on the select element but none of the option elements have the selected attribute, then no element is selected by default. (Tested on IE 9, FF 5, Chrome 13, and Safari 5 on Win 7.)

So, what should the web browser do if the user doesn't select anything yet submits the form? It should do exactly what you would expect: Submit no selection. And that's exactly what the current version of the HTML5 spec says:

"The multiple attribute is a boolean attribute. If the attribute is present, then the select element represents a control for selecting zero or more options from the list of options."

http://dev.w3.org/html5/spec/Overview.html#the-select-element