显示列表

Js 中操作 Select 元素
1.增加项
var objSelect = document.getElementById('ID');
objSelect.options[objSelect.length] = new Option('Key', 'Value');

2.删除被选中的项
objSelect.options[objSelect.selectedIndex] = null;

3.修改被选中的项
objSelect.options[objSelect.selectedIndex] = new Option('Key', 'Value');

4.获取被选中的项的文本
objSelect.options[objSelect.selectedIndex].text;

5.获取被选中的项的值
objSelect.options[objSelect.selectedIndex].value;

6.设置选中的项
objSelect.value = value;




返回摘要 | 分类(JavaScript) | 访问(119) | 编辑