日期:2014-05-16  浏览次数:20359 次

请求一个小问题,请大家帮忙?
有字符串:
str plist="1-小明|2-小强|3-小娟|4-小狗...." //数字表示人员ID,汉字表示姓名
如何他显示在下拉菜单(dbl_list)里面,谢谢各位

------解决方案--------------------
<html>
<head>
<title>测试页面</title> 
<script type="text/javascript">
function test(){
var plist="1-小明 ¦2-小强 ¦3-小娟 ¦4-小狗"; 
var s = new Array();
s=plist.split(" ¦"); 
for(i=0;i<s.length;i++){ 
var zaire = new Option(s[i], // The text property 
s[i], // The value property 
false, // The defaultSelected property 
false); // The selected property
// Display it in a Select element by appending it to the options array: 
var countries = document.all.man; // Get the Select object 
countries.options[i] = zaire;
}

</script>
</head> 
<body>
<div align="center">
<select id="man" name="man" style="width: 130px;">
<option>--请选择--</option>
</select> 
<input type="button" name="but" value="添加下拉列表" onclick="test()">
</div>
</body>
</html>
------解决方案--------------------
JScript code

var flag=false;
function addOptions()
{
   if(!flag)
   {
      var plist="1-小明 ¦2-小强 ¦3-小娟 ¦4-小狗";
      var arrList=plist.split("|");
      for(var i in arrList)
      {
         var newItem=new Option(arrList[i],arrList[i]);
         $("nameList").options[$("nameList").length]=newItem;
      }
      flag=true;
   }
}
function $(objID)
{
   return document.getElementById(objID);
}