/** Test for HTMLSelectElement's selectedOptions attribute.
*
* selectedOptions is a live list of the options that have selectedness of true
* (not the selected content attribute).
*
* See http://www.whatwg.org/html/#dom-select-selectedoptions
**/
function checkSelectedOptions(size, elements)
{
is(selectedOptions.length, size, "select should have " + size + " selected options");
for (let i = 0; i < size; ++i) {
ok(selectedOptions[i], "selected option is valid");
if (selectedOptions[i]) {
is(selectedOptions[i].value, elements[i].value, "selected options are correct");
}
}
}
let select = document.createElement("select");
document.body.appendChild(select);
let selectedOptions = select.selectedOptions;
ok("selectedOptions" in select, "select element should have a selectedOptions IDL attribute");
ok(select.selectedOptions instanceof HTMLCollection, "selectedOptions should be an HTMLCollection instance");
let option1 = document.createElement("option");
let option2 = document.createElement("option");
let option3 = document.createElement("option");
option1.id = "option1";
option1.value = "option1";
option2.value = "option2";
option3.value = "option3";
option1.selected = false;
// Usinig selected directly on the option should work.
checkSelectedOptions(1, [option2]);
select.remove(1); select.add(option2, 0); select.options[0].selected = true; select.options[1].selected = true;
// Should be in tree order.
checkSelectedOptions(2, [option2, option1]);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.