This time I bring you jQueryDynamic display of selectdrop-down list data, what are the precautions for jQuery to dynamically display select drop-down list data, the following are Let’s take a look at practical cases.
Let’s take a look at the running effect first:
The specific code is as follows:
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>jQuery动态显示表单</title> <script type="text/javascript" src="jquery-1.7.1.min.js"></script> <script type="text/javascript"> //数据集 var schools = [ { 'id': 1, 'name': '南京大学' }, { 'id': 2, 'name': '北京大学' }, { 'id': 3, 'name': '浙江大学' }, { 'id': 4, 'name': '清华大学' }, { 'id': 5, 'name': '湖南大学' }, ]; //页面加载运行,将数据集绑定select,显示默认选中学校 $(function () { bindSelect(); $('#info').text($('#schoolSelect').val()); }); //将数据集绑定select,重新选择学校后显示选中学校 bindSelect = function () { var $schoolSelect = $('#schoolSelect'); $schoolSelect.change(function () { $('#info').text($(this).val()); }); if (schools.length > 0) { for (var i = 0; i < schools.length; i++) { var item = schools[i]; if (item.id == 2) { $schoolSelect.append('<option value="' + item.id + '" selected>' + item.name + '</option>'); } else { $schoolSelect.append('<option value="' + item.id + '">' + item.name + '</option>'); } } } } </script> </head> <body> <form> <select id="schoolSelect"> </select> <label id="info"></label> </form> </body> </html>
I believe I have read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Detailed explanation of the use of full-screen scrolling plug-in fullpage.js
How to prevent the same event from being triggered repeatedly
How to automatically load more content when the scroll bar slides to the bottom
The above is the detailed content of jQuery dynamically displays select drop-down list data. For more information, please follow other related articles on the PHP Chinese website!