当前位置:首页 >> 网络编程

IE8下Jquery获取select选中的值post到后台报错问题

我们一般使用jquery获取select时,一般这么用:

<select id='a'> 
<option selected='selected' value='1'> 
</select> 
var selectedValue = $("#a").val();

在非IE8下,selectedValue的值为“1”,typeof selectedValue 为“string”。

在IE8下,selectedValue的值为[“1”],typeof selectedValue 为 “objectg”。

如果直接将selectedValue post发送到后台,后台接收时会报错,因为在传输过程中,IE8下selectedValue当成了数组,后台无法识别。

解决的代码如下:

selectedValue = typeof selectedValue == "object" "htmlcode">
var a = selectedValue.trim();

这段代码在IE8下无法执行,可能的原因也是由于上述所致。

"htmlcode">

$.trim(selectedValue);