Home >Web Front-end >JS Tutorial >JS acquisition, addition, and deletion operations for HTML tag select_javascript skills

JS acquisition, addition, and deletion operations for HTML tag select_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:19:521076browse
Copy code The code is as follows:



Copy code The code is as follows:

/ /Get html control
var select = document.getElementsByName("aaa")[0];

select.selectedIndex = index;
//Create a new Option object
new Option( text, value)
new option(text, value, defaultSelected, selected
text: string, specifying the text attribute of the option object (that is, the text between )
value: String, specify the value attribute of the option object
defaultSelected: Boolean value, specify the defaultSelected attribute of the option object
selected: Boolean value, specify the selected attribute of the option object

//To select Add Option
select.add(new Option(text,value))

//Delete
select.options.remove(index)
//Delete all
select at once .length = 0;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn