posts - 325,  comments - 25,  trackbacks - 0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function addList(){
    
var list = document.getElementById("list");
    
for(var i = 1; i <= 5; i++){
        
var newOption = document.createElement("option");
        newOption.setAttribute(
"value", i);
        newOption.appendChild(document.createTextNode(
"测试数据" + i));
        list.appendChild(newOption);
    }

}


function clearList(){
    
var list = document.getElementById("list");
    
    
for(var i = list.options.length; i >= 0; i--){
        list.remove(i);
    }

    
//注意:每删除一个option其它option的index特性会自动重置,因此,按以下方法(即从上往下删是清除不了的)
    //for(var i = 0; i< list.options.length; i++){
    //    list.remove(i);
    //}
}

</script>
</head>
<body>
<select name="list" id="list">
</select>
<input type="button" onclick="addList()"  value="生成"/>
<input type="button" onblur="clearList()" value="清空" />
</body>
</html>
posted on 2008-08-26 14:46 长春语林科技 阅读(264) 评论(0)  编辑  收藏 所属分类: js

只有注册用户登录后才能发表评论。


网站导航:
 
<2008年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

 

长春语林科技欢迎您!

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜