select
http://sunxin1001.iteye.com/blog/740314
http://www.w3school.com.cn/htmldom/met_select_add.asp
在下拉列表末尾添加选项
<html>
<head>
<script type="text/javascript">
function insertOption()
{
var y=document.createElement('option');
y.text='Kiwi'
var x=document.getElementById("mySelect");
try
{
x.add(y,null); // standards compliant
}
catch(ex)
{
x.add(y); // IE only
}
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<input type="button" οnclick="insertOption()"
value="Insert option" />
</form>
</body>
</html>
在下拉列表选项之前添加选项
<html>
<head>
<script type="text/javascript">
function insertBeforeSelected()
{
var x=document.getElementById("mySelect");
if (x.selectedIndex>=0)
{
var y=document.createElement('option');
y.text='Kiwi';
var sel=x.options[x.selectedIndex];
try
{
x.add(y,sel); // standards compliant
}
catch(ex)
{
x.add(y,x.selectedIndex); // IE only
}
}
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<input type="button" οnclick="insertBeforeSelected()" value="Insert option before selected" />
</form>
</body>
</html>
其他参考
//option选项
<select id="myselect" size="1"> <option value=""></option> </select> <script type="text/javascript"> $('#myselect').append('<option value="test1">test1</option>'); $('#myselect').append('<option value="test2">test2</option>'); </script>
$(document).ready(function() { $('#myselect').append('<option value="test1">test1</option>'); $('#myselect').append('<option value="test2">test2</option>'); });
ie6不能识别option标签的selected属性解决方案
今天在做省份联动的时候,在ie6下创建下拉菜单始终报js脚本错误(找不到selected属性),调来调去始终发现ie6下不能识别option的selected属性,试了好多种创建option的方式都不行.结果发现ie6下有这么一个Bug,ie的其他版本都不存在这个问题,从网上查了一下,终于解决了这个棘手的问题:
解决方案:
function doCreateDropDownList() {
var obj = document.getElementById("selectName");
var op = new Option("--请选择--","0");
obj.options.add(op);
...........
...........
}
http://sunxin1001.iteye.com/blog/740314
http://www.w3school.com.cn/htmldom/met_select_add.asp
在下拉列表末尾添加选项
<html>
<head>
<script type="text/javascript">
function insertOption()
{
var y=document.createElement('option');
y.text='Kiwi'
var x=document.getElementById("mySelect");
try
{
x.add(y,null); // standards compliant
}
catch(ex)
{
x.add(y); // IE only
}
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<input type="button" οnclick="insertOption()"
value="Insert option" />
</form>
</body>
</html>
在下拉列表选项之前添加选项
<html>
<head>
<script type="text/javascript">
function insertBeforeSelected()
{
var x=document.getElementById("mySelect");
if (x.selectedIndex>=0)
{
var y=document.createElement('option');
y.text='Kiwi';
var sel=x.options[x.selectedIndex];
try
{
x.add(y,sel); // standards compliant
}
catch(ex)
{
x.add(y,x.selectedIndex); // IE only
}
}
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<input type="button" οnclick="insertBeforeSelected()" value="Insert option before selected" />
</form>
</body>
</html>
其他参考
//option选项
<select id="myselect" size="1"> <option value=""></option> </select> <script type="text/javascript"> $('#myselect').append('<option value="test1">test1</option>'); $('#myselect').append('<option value="test2">test2</option>'); </script>
$(document).ready(function() { $('#myselect').append('<option value="test1">test1</option>'); $('#myselect').append('<option value="test2">test2</option>'); });
ie6不能识别option标签的selected属性解决方案
今天在做省份联动的时候,在ie6下创建下拉菜单始终报js脚本错误(找不到selected属性),调来调去始终发现ie6下不能识别option的selected属性,试了好多种创建option的方式都不行.结果发现ie6下有这么一个Bug,ie的其他版本都不存在这个问题,从网上查了一下,终于解决了这个棘手的问题:
解决方案:
function doCreateDropDownList() {
var obj = document.getElementById("selectName");
var op = new Option("--请选择--","0");
obj.options.add(op);
...........
...........
}