用javascript操作select(DropDownList)
<select ID="ddl_SortID" Width="120px">
<option Value="1">A</option>
<option Value="2">B</option>
<option Value="3">C</option>
</select>
<script language="javascript">
<!--
var ddl = document.getElementById('ddl_SortID');
var itemCount = ddl.options.length;
for (var i = 0; i < itemCount; i ++)
{
//让Value="2"的那一项选中
//也可以用ddl.value = "2";
if (dd1.options[i].value == '2')
{
ddl.selectedIndex = i;
}
//让Text="C"的那一项选中
if (dd1.options[i].innerText == 'C')
{
ddl.selectedIndex = i;
}
//删除A项
if (dd1.options[i].innerText == 'A')
{
ddl.removeChild(ddl.options[i]);
}
//4添加value='4' text='D' 这一项
var optNew = document.createElement('option');
optNew.text = 'D';
optNew.value = '4';
try
{
ddl.add(optName);//仅对IE
}
catch(ex)
{
ddl.add(elOptNew, null); //对非IE
}
}
-->
</script>