Home >Web Front-end >JS Tutorial >jquery dynamically add option example_jquery

jquery dynamically add option example_jquery

WBOY
WBOYOriginal
2016-05-16 17:06:001349browse

jquery dynamically adds option

js dynamically add option

Copy code The code is as follows:

var sel= document.getElementById("Selected1");
sel.options.add(new Option("Please select",""));
sel.options.add(new Option("name","id"));

jquery dynamically adds option

Copy code The code is as follows:

$("#selectId").append("< ;option value='" value "'>" text "");

jquery removes all options

Copy code The code is as follows:

$("#selectedId option").remove() ;
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