js 动态 增加 删除 select 子项 option
来源:互联网 发布:node.js php 对比 编辑:程序博客网 时间:2024/05/21 14:03
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="content-type" content="text/html; charset=GBK">
<title>js 动态 增加 删除 select 子项option</title>
<script type="text/javascript">
function addOption(){
var obj=document.getElementById("test");
var index=obj.options.length;
obj.options.add(new Option("子项"+index,index));
}
function delOption(){
var obj=document.getElementById("test");
if(0<obj.options.length){
//obj.options.remove(obj.selectedIndex); //IE 可用
obj.options[obj.selectedIndex]=null;//IE FF 均可
for(var i=0;i<obj.options.length;i++){//for 只为重新排序...可以忽略
obj.options[i].text="子项"+i;
obj.options[i].value=i;
}
if(0<obj.options.length){//第一项选择状态
obj.options[0].selected=true;
}
}
}
function delAll(){
var obj=document.getElementById("test");
obj.options.length=0;
}
function selectIndex(){
var obj=document.getElementById("test");
if(0<obj.options.length){
var option=obj.options[obj.selectedIndex];
alert("当前选中项索引="+obj.selectedIndex+";text="+option.text+";value="+option.value);
}
}
</script>
</head>
<body >
<select id='test'style='width:100px;'>
</select>
<input type='button' value='添加' onclick='addOption()'/>
<input type='button' value='删除当前选中项' onclick='delOption()'/>
<input type='button' value='删除全部' onclick='delAll()'/>
<input type='button' value='当前选中项信息' onclick='selectIndex()'/>
</body>
</html>
<html >
<head>
<meta http-equiv="content-type" content="text/html; charset=GBK">
<title>js 动态 增加 删除 select 子项option</title>
<script type="text/javascript">
function addOption(){
var obj=document.getElementById("test");
var index=obj.options.length;
obj.options.add(new Option("子项"+index,index));
}
function delOption(){
var obj=document.getElementById("test");
if(0<obj.options.length){
//obj.options.remove(obj.selectedIndex); //IE 可用
obj.options[obj.selectedIndex]=null;//IE FF 均可
for(var i=0;i<obj.options.length;i++){//for 只为重新排序...可以忽略
obj.options[i].text="子项"+i;
obj.options[i].value=i;
}
if(0<obj.options.length){//第一项选择状态
obj.options[0].selected=true;
}
}
}
function delAll(){
var obj=document.getElementById("test");
obj.options.length=0;
}
function selectIndex(){
var obj=document.getElementById("test");
if(0<obj.options.length){
var option=obj.options[obj.selectedIndex];
alert("当前选中项索引="+obj.selectedIndex+";text="+option.text+";value="+option.value);
}
}
</script>
</head>
<body >
<select id='test'style='width:100px;'>
</select>
<input type='button' value='添加' onclick='addOption()'/>
<input type='button' value='删除当前选中项' onclick='delOption()'/>
<input type='button' value='删除全部' onclick='delAll()'/>
<input type='button' value='当前选中项信息' onclick='selectIndex()'/>
</body>
</html>
- js 动态 增加 删除 select 子项 option
- js 动态 增加 删除 select 子项 option
- js动态增加、插入、修改、删除option
- js select 增加option
- 动态增加、删除select 里的option的小例子
- select动态添加子选择项option
- JS动态添加与删除select中的Option对象
- js对select动态添加和删除OPTION
- 使用js对select动态添加和删除OPTION
- javascript--使用js对select动态添加和删除OPTION
- 【转】js对select动态添加和删除OPTION
- js对select动态添加和删除OPTION
- js select option添加/删除
- jQuery 增加 删除 修改select option
- jQuery 增加 删除 修改select option .
- jQuery 增加 删除 修改select option
- jQuery 增加 删除 修改select option
- jQuery 增加 删除 修改select option
- 关于Arrays的asList()
- 修改Google Chrome浏览器背景颜色的方法
- [转载]Qt 调用外部exe的方法
- AsyncTask
- select 模式
- js 动态 增加 删除 select 子项 option
- 杭电2710-Max Factor
- 常见的Hash算法
- ExtJS列表控件实现CRUD操作
- Maximal Rectangle
- InitializingBean和DisposableBean
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- Outlook设置Gmail邮箱步骤
- 使用Axis创建Web Service服务