首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

请小疑点,请大家帮忙

2012-02-13 
请求一个小问题,请大家帮忙?有字符串:str plist1-小明|2-小强|3-小娟|4-小狗....//数字表示人员ID,汉字

请求一个小问题,请大家帮忙?
有字符串:
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);} 

热点排行