jQuery dynamically generates select option drop-down list implementation code

小云云
Release: 2018-01-22 13:52:40
Original
1308 people have browsed it

There are many ways to implement the select option drop-down list. This article mainly introduces the implementation method of jQuery dynamically generating the select option drop-down list. Friends who need it can refer to it. I hope it can help everyone.

But there is no implementation of dynamically generating the select option drop-down list.

It is very convenient to create jQuery objects in the jQuery environment to achieve dynamic generation.

Prepare some data in the database:

Stored procedure:

Develop ASP.NET MVC, to implement the program, requires model:

Now create an entity Entity, which is to communicate with the database:

Next, you can create a method to get the data set and let the front-end jQuery execute the method:

ok, everything is ready.

Create a select object:

$selectCity = $('').attr({ name: 'city', class: 'selectcity' });

You can create an empty option:

$("", { value: "", text: "" }).appendTo($selectCity );

The data read from the database can now dynamically generate option:

If you need to bind a selection value when displaying, then How to achieve it? It's very simple. When $.each, judge:

The "3" above is a variable, which is the value you need to bind. The following is a demonstration of the effect:

Related recommendations:

HTML select option detailed description

Detailed explanation of how to make default selection in Html Select option

JS & JQuery dynamically add select option

The above is the detailed content of jQuery dynamically generates select option drop-down list implementation code. For more information, please follow other related articles on the PHP Chinese website!

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 Recommendations
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!