The drop-down list function gets the data and adds it to the select table

<!DOCTYPE html >
<html>

<head>
<meta charset="utf-8">
<title> Hello MUI</title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<style>
</style>
</head>
<body>
<select class="textPrepend" autofocus = "autofocus" _multiple = "multiple">
<option value ="">请选择</option>
  <!--<option value ="1">周一</option>
  <option value ="2">周二</option>
  <option value="3">周三</option>
  <option value="4">周四</option>-->
</select>
<button class="textclas">Submit</button>

<script src="jquery-1.7.2.min.js"></script>
<script>

$(function(){
/*Array add To the drop-down list
* var _mozi=['Mojia','Mozi','Mo Zhai','Jiangaifeigong','Shangtong Shangxian'];
$.each(_mozi,function(key,val) {
    //The callback function has two parameters, the first is the element index, the second is the current value
    var num=key+1;
    $('.textPrepend').prepend('<option value="'+key+' ">'+val+'</option>');
})*/
/*The json array read data is added to the select drop-down list
* var people = { "programmers": [ { "firstName": "Brett", " lastName":"McLaughlin", "email": " aaaa" },

{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },

{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
]}
people = eval(people.programmers);
for(var i=0; i<people.length; i++)
{
$('.textPrepend').prepend('<option value ="'+[i]+'">'+people[i].firstName+'</option>');
}*/
/*遍历json对象添加到select下拉列表中
* var people= [ { "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },

{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },

{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
]
$.each(people, function(idx, obj) {
    $('.textPrepend').prepend('<option value ="'+idx+'">'+obj.firstName+'</option>');
});*/
});

$('.textclas').on('click',function(){
alert('取到的数值是:'+$('.textPrepend').val());
});
</script>
</body>

</html>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326848805&siteId=291194637