欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript實現(xiàn)將數(shù)組數(shù)據(jù)添加到Select下拉框的方法

 更新時間:2015年08月21日 09:29:37   作者:佚名  
這篇文章主要介紹了JavaScript實現(xiàn)將數(shù)組數(shù)據(jù)添加到Select下拉框的方法,涉及javascript數(shù)組操作及頁面元素動態(tài)賦值的相關(guān)技巧,需要的朋友可以參考下

本文實例講述了JavaScript實現(xiàn)將數(shù)組數(shù)據(jù)添加到Select下拉框的方法。分享給大家供大家參考。具體如下:

這里演示將數(shù)組中的數(shù)據(jù)添加到Select下拉菜單中的效果,當(dāng)你點擊下拉框的時候,就動態(tài)加載了數(shù)據(jù),更換Select內(nèi)容的時候,直接替換數(shù)組中的內(nèi)容就可以了。適合前端設(shè)計者實現(xiàn)前臺的部分本地化腳本操作。

運(yùn)行效果截圖如下:

在線演示地址如下:

http://demo.jb51.net/js/2015/js-array-add-select-data-codes/

具體代碼如下:

<!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>將數(shù)組中的數(shù)據(jù)添加到下拉菜單中</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 ">將數(shù)組中的數(shù)據(jù)添加到下拉菜單中</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">&nbsp;</td>
  </tr>
  </table>
 </form></td>
 </tr>
</table>
</body>
</html>

希望本文所述對大家的javascript程序設(shè)計有所幫助。

相關(guān)文章

最新評論