<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>动态生成下拉框选项</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
//动态生成下拉框选项
$(document).ready(function(){
var info = ' ';
var data = ['Volvo','Saab','er','ar','da','da','ad','add','ad'];
$.each(data ,function(index,i){
info +=" <option value=' "+index+ " '> " + i + "</option>";
});
$("#st").append(info);
});
//获取选择框的值
function mySelect(){
var st = $("#st");
alert(st.val());
}
</script>
</head>
<body>
<select id="st" style="width:500px" >
</select>
<button onclick="mySelect()">获取值</button>
</body>
</html>
动态生成下拉框,并获取下拉框的值
最新推荐文章于 2024-04-26 10:14:46 发布