Home > Web Front-end > JS Tutorial > body text

jQuery operation option implementation code_jquery

WBOY
Release: 2016-05-16 18:10:04
Original
1115 people have browsed it

Clear the option before clearing the option in js. My approach is to traverse the existing option and make each of its child elements empty. Now using jQuery to implement it, we only need to call its supported empty method.

empty()

Delete all child nodes in the matching element set.
In addition, we need to set the default value, so here is the method to clear all options under select, just use the following statement:

Copy code The code is as follows:

$('#selectId').empty().append( $("") );

The previous method of dynamically creating option
with js was to use its intermediate function to traverse the json object returned by Ajax. And use new Option to create option. Now I use the following method to process
Copy code The code is as follows:

for(var i = 0,len = jsondata.length; i$('#selectId').append($(""));
}

It seems that it can also be written like this:
Copy code The code is as follows:

$('#selectId').append("");
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!