Home > Article > Web Front-end > jQuery dynamically generates select option drop-down list implementation code
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!