js在IE下获取不了html的select标签值
我在html页面里加入了select标签:
<select size="1" id="expertOrQuery" name="expertOrQuery"onchange="class_onchange()" ><option>专家</option><option>咨询</option></select>?
?
在提交前用js进行判断,在点击按钮的触发事件里加入如下方法:
function beforeSearch(){//var searchType = $("expertOrQuery").value;var searchType = document.getElementById("expertOrQuery").value;if(searchType == "专家"){searchExpert();}else if(searchType == "咨询"){searchQuestion();}}?
?
但是在IE下老点击也没反应,用firefox或都chrome都是有反应的,后来在beforeSearch方法里加入了alert来一个个判断,才知道用document.getElementById("expertOrQuery").value;方法在IE下是获取不了值的。
后来改为使用如下的方式就可以解决这个IE不识别select标签值的问题:
function beforeSearch(){//var searchType = $("expertOrQuery").value;//var searchType = document.getElementById("expertOrQuery").value;var searchType=document.getElementById("expertOrQuery").options[document.getElementById("expertOrQuery").options.selectedIndex].valueif(searchType == "专家"){searchExpert();}else if(searchType == "咨询"){searchQuestion();}}?