Js获取下拉框的值和文本网上提供了2种方法:但有些人很不负责任,他们根本没考虑到浏览器之间的差异导致的错误,导致很多新手琢磨了半天找不出错误! 下面我总结下Firefox和IE下获取下拉框选定项的值和文本: 1. IE和Firefox都支持的方法: 获取文本 var obj=document.getElementById('select_template'); var text=obj.options[obj.selectedIndex].text;//获取文本 var obj=document
js获取select选中的值: var sel=document.getElementById("select1"); var index = sel.selectedIndex; // 选中索引 albumid= sel.options[index].value;//要的值 jQuery获取下拉框选中的option: $("#s option:selected").val();
sp中定义 js中初始化 //年度下拉框初始化 $("#yearChoose").combobox({ valueField:'year', textField:'year', panelHeight:'auto' }); var data = [];//创建年度数组 var startYear;//起始年份 var thisYear=new Date().getUTCFullYear();//今年 var endYear=thisYear+1;//结束年份 //数组