如何用jquery将一个数组绑定到下拉框中?
1个回答
展开全部
简单,给你写个简单的
<html>
<head>
<title>test</title>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
</head>
<script>
$().ready(function(){
var arrYear = new Array();
var date = new Date();
var year= date.getFullYear();
for (var i=0;i<=10;i++){
arrYear.push(year-i);
}
$.each(arrYear, function (i) {
$("#selYear").append("<option value='" + i + "'>" + arrYear[i] + "</option>");
});
$("#selYear").unbind();
$("#selYear").bind("change", function () {
alert("当前选择-----索引:" +$("#selYear").val()+ "---值:" + $("#selYear").find("option:selected").text());
});
});
</script>
<body>
<select id="selYear" style="width:140px"></select>
</body>
</html>
<html>
<head>
<title>test</title>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
</head>
<script>
$().ready(function(){
var arrYear = new Array();
var date = new Date();
var year= date.getFullYear();
for (var i=0;i<=10;i++){
arrYear.push(year-i);
}
$.each(arrYear, function (i) {
$("#selYear").append("<option value='" + i + "'>" + arrYear[i] + "</option>");
});
$("#selYear").unbind();
$("#selYear").bind("change", function () {
alert("当前选择-----索引:" +$("#selYear").val()+ "---值:" + $("#selYear").find("option:selected").text());
});
});
</script>
<body>
<select id="selYear" style="width:140px"></select>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询