select动态增加option
2015-05-20 23:41
260 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>option creation</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
body {
}
#container {
width:400px;
text-align:center;
padding: 20px 0px;
border: 3px double #000;
margin:30px auto;
}
/*//]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
var opts=3 /*number of original options*/
var df=document.forms;
function optionAdd(num) {
opts=opts+num;
df[0][0].options.length=opts;
df[0][0].options[opts-1].innerHTML=df[0][1].value;
df[0][1].value=""
}
//]]>
</script>
</head>
<body>
<form action="#">
<div id="container">
<select>
<option>- - - - - - - - </option>
<option>option one</option>
<option>option two</option>
</select>
<input type="text" />
<input type="button" value="new option" onclick="optionAdd(1)"/>
</div>
</form>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>option creation</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
body {
}
#container {
width:400px;
text-align:center;
padding: 20px 0px;
border: 3px double #000;
margin:30px auto;
}
/*//]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
var opts=3 /*number of original options*/
var df=document.forms;
function optionAdd(num) {
opts=opts+num;
df[0][0].options.length=opts;
df[0][0].options[opts-1].innerHTML=df[0][1].value;
df[0][1].value=""
}
//]]>
</script>
</head>
<body>
<form action="#">
<div id="container">
<select>
<option>- - - - - - - - </option>
<option>option one</option>
<option>option two</option>
</select>
<input type="text" />
<input type="button" value="new option" onclick="optionAdd(1)"/>
</div>
</form>
</body>
</html>
相关文章推荐
- 使用js 在IE和火狐firfox 里动态增加select 的option
- select动态增加option
- js 动态 增加 删除 select 子项 option
- select中,动态增加option 并设置当前选中值
- 使用js 在IE和火狐firfox 里动态增加select 的option
- js 动态 增加 删除 select 子项 option
- select动态增加option
- dojo小例子(20)动态加载的Select增加一个option空白项
- 动态增加、删除select 里的option的小例子
- Jquery multiselect 多选下拉框与ajax配合使用,动态拼接option。初始化默认选中多个,增加搜索框
- select 动态填充option选项及获取选择的值或者所有值
- jquery根据value来动态选中select下的option
- .动态创建selectjs 操作select和option(转载)
- 关于动态操作select的option的值的问题
- jQuery 增加 删除 修改select option .
- 实现select动态添加option并选中的多种方法
- 动态创建selectjs 操作select和option(转载)
- 使用js对select动态添加和删除OPTION示例代码
- JS动态创建Select的option
- javascript 只知道select的option的value值 动态设置它得值