08-03
03
下拉表单的添加删除
作者:Java伴侣 日期:2008-03-03
<html>
<head><title>添加删除选中下拉表单</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<table width="80%" border="1">
<form action="" method="`post" name="myform">
<tr>
<td>
<select name="city" id="city" multiple="multiple" style="width:400px;margin:-3px 0 -3px -3px">
<option value="1" >选1</option>
<option value="2">选2</option>
<option value="3">选3</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="button" name="but_1" value="添加下列表" onclick="addOption();" />
<input type="button" name="but_1" value="删除下列表" onclick="delOption();" />
<input type="button" name="but_1" value="选中下列表" onclick="chOption();" />
</td>
</tr>
</form>
</table>
<script language="javascript">
function $(id)
{
return document.getElementById(id);
}
function addOption()
{
var obj=$('city').options;
var op = document.createElement("option"); //创建节点
op.value="asdf";
op.text="asdf";
//var inserto = new Option('-1003-', '1003'); //或直接这样创建接点
obj.add(op);
}
function delOption(id)
{
var obj=$('city').options;
obj[0]=null; //直接删除
}
function chOption()
{
//var obj=$('city').options;
//obj[2].selected=true;
var obj=$('city');//或直接用这个选定值
obj.value=2;
}
</script>
</body>
</html>
<head><title>添加删除选中下拉表单</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<table width="80%" border="1">
<form action="" method="`post" name="myform">
<tr>
<td>
<select name="city" id="city" multiple="multiple" style="width:400px;margin:-3px 0 -3px -3px">
<option value="1" >选1</option>
<option value="2">选2</option>
<option value="3">选3</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="button" name="but_1" value="添加下列表" onclick="addOption();" />
<input type="button" name="but_1" value="删除下列表" onclick="delOption();" />
<input type="button" name="but_1" value="选中下列表" onclick="chOption();" />
</td>
</tr>
</form>
</table>
<script language="javascript">
function $(id)
{
return document.getElementById(id);
}
function addOption()
{
var obj=$('city').options;
var op = document.createElement("option"); //创建节点
op.value="asdf";
op.text="asdf";
//var inserto = new Option('-1003-', '1003'); //或直接这样创建接点
obj.add(op);
}
function delOption(id)
{
var obj=$('city').options;
obj[0]=null; //直接删除
}
function chOption()
{
//var obj=$('city').options;
//obj[2].selected=true;
var obj=$('city');//或直接用这个选定值
obj.value=2;
}
</script>
</body>
</html>
评论: 0 | 引用: 0 | 查看次数: 627
发表评论