分类分类
更新时间:2026-09-29 18:55:31作者:yezheng
本文实例讲述了JavaScript实现将数组数据添加到Select下拉框的方法。分享给大家供大家参考。具体如下:
这里演示将数组中的数据添加到Select下拉菜单中的效果,当你点击下拉框的时候,就动态加载了数据,更换Select内容的时候,直接替换数组中的内容就可以了。适合前端设计者实现前台的部分本地化脚本操作。
运行效果截图如下:

具体代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>将数组中的数据添加到下拉菜单中</title>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
<script type="text/javascript">
var counts;
counts=0;
arr = new Array("JavaScript与ASP","JavaScript与JSP","JavaScript与ASP.NET","JavaScript与PHP");
counts=arr.length;
function Myselect(){
var i;
for (i=0;i < counts; i++) {
document.form1.sel.options[i] = new Option(arr[i],i);
}
}
</script>
</head>
<body>
<table width="280" height="160" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td height="34" align="center"><span class="style1" style="font-weight:bold ">将数组中的数据添加到下拉菜单中</span></td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#9ACCFF"><form name="form1">
<table width="235" height="69" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="21"><select name="sel" id="sel" onFocus="Myselect()">
</select></td>
</tr>
<tr>
<td height="120"> </td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
相关
群英争雄策略游戏1007.72 Mv1.0.12026-09-29
下载梦漫app资讯阅读43.14 Mv1.0.12026-09-29
下载点点大作战经营养成623.91 Mv2.6.2002026-09-29
下载妖怪名单角色扮演13.64 Mv1.0.02026-09-29
下载可露优世界休闲益智790.16 Mv9.92.31.102026-09-29
下载OverPeak超人游戏角色扮演304.38 Mv0.62026-09-29
下载宇宙回形针休闲益智24.07 Mv2.1.282026-09-29
下载pvzrhlauncher启动器手游辅助91.98 Mv1.1.1-ci.5492026-09-29
下载玛雅纪元角色扮演884.12 Mv2.1.122026-09-29
下载倒水倒不停红包版休闲益智68.28 Mv1.0.42026-09-29
下载观心心理(心理成长服务)生活服务208.9 MBv2.0.42026-09-29
下载速查驾规(交通法规速查)生活服务91.6 MBv1.0.02026-09-29
下载










