HTML <select>,而不是 <select multiple>:选择多个选项时的行为

HTML <select>, not <select multiple>: behavior when more than one option is selected

this simple jsfiddle(下面的代码)中,我有一个常规的 <select>,而不是 <select multiple>,有两个具有 selected 属性的选项。在 Chrome 39 中,我看到 "d" selected。显然,行为是 select "selected" 选项的最后一个,这似乎合乎逻辑。 我可以跨浏览器使用这种行为吗?

<select>
    <option value="a">a</option>
    <option value="b" selected>b</option>
    <option value="c">c</option>
    <option value="d" selected>d</option>
</select>

A select element whose multiple attribute is not specified must not have more than one descendant option element with its selected attribute set.

来源w3.org

所以它无效 HTML 因此浏览器的行为是不可预测的。如果您通过 Javascript 创建了这些选定的选项,您也许也应该通过 JS 处理您想要的行为。