ITeye博客

用javascript操作select

netxdiy · 2007-06-15 09:36 · Markdown

1 检测是否有选中
if(objSelect.selectedIndex > -1) {
//说明选中
} else {
//说明没有选中
}
2 删除被选中的项
objSelect.options[objSelect.selectedIndex] = null;
3 增加项
objSelect.options[objSelect.length] = new Option("你好","hello");
4 修改所选择中的项
objSelect.options[objSelect.selectedIndex] = new Option("你好","hello");
5 得到所选择项的文本
objSelect.options[objSelect.selectedIndex].text;
6 得到所选择项的值
objSelect.options[objSelect.selectedIndex].value;

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。