日期:2014-05-16  浏览次数:20429 次

JS Select的动态取值(Text,value),添加,删除。兼容IE
<script language="javascript">
function addSel(o,o1,o2)
{
    o.options.add(new Option(o2.value,o1.value));
}
function delSel(o)
{
    o.options.remove(o.selectedIndex);
    o.selectIndex=0;
}
function getValue(o)
{
    alert("Text :"+o.options[o.selectedIndex].text+"\nValue:"+o.value);
}
</script>
<select id="sel">
<option value="1">11111</option>
<option value="2">22222</option>
</select>
value:<input id="addV" type="text">
text:<input id="addT" type="text">
<input type="button" value="添加" onclick="addSel(document.getElementById('sel'),document.getElementById('addV'),document.getElementById('addT'))">
<input type="button" value="删除" onclick="delSel(document.getElementById('sel'))">

<input type="button" value="取值" onclick="getValue(document.getElementById('sel'))">

?