select

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);
...........
...........
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值