<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>
<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>
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].substr(2), // The text property
s[i].substr(0,1), // 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;
}
}
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);
}
<select id="nameList">
<option>please select</option>
</select>
<input type="button" value="add options" onclick="addOptions()">================================================================
基本是這樣.
var newItem=new Option(arrList[i].substring(2),arrList[i].substring(0,1));
=========================================================================
可以試試.
function test(){
var plist="name1¦name2 ¦name3 ¦name4";
var s=plist.split(" ¦");
for(i=0;i <s.length;i++){
var zaire = new Option(s[i].substr(2) //显示名字,i //人名的序号);
var countries = document.all.man;
countries.options[i] = zaire;
}
}加分吧!