您的位置:首页 > 运维架构

下拉列表框,动态添加删除OPTION

2011-03-31 17:52 417 查看
<html>
<head>
<title>option test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<input type="radio"  name="rd" onclick="change(1)">11
<input type="radio" name="rd"  onclick="change(2)">22

<select name='change'>
<option value="" >请选择</option>
<option value="1" id="op1">1</option>
<option value="2" id="op2">2</option>
<option value="3" id="op3">3</option>
<option value="4" id="op4">4</option>

</select>

<mce:script type="text/javascript"><!--
function change(id){
var chg=document.getElementById("change");
if(id==1){

chg.length=1;//清空OPTION
//动态添加OPTION
chg.options.add(new Option("第一项","1"));//左边显示,右边为值;

}else{
//从后一个个删除OPTION
chg.remove(4);
chg.remove(3);
chg.remove(2);
chg.remove(1);
chg.options.add(new Option("测试项","123"),2);//2表示插入第几行

}

}
// --></mce:script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: