jQuery取得select选中的值

记录一下。

本来以为$("#vitNeedreply").val();是取得选中的值,

那么$("#vitNeedreply").text();就是取得的文本。

alert($("#vitNeedreply").val());出来的值是正确的

但实际上$("#vitNeedreply").val();取得的是一个Object,是一个数组。要是直接用这个值的话,有些地方会报类型不匹配(如mybits里的XXquery.java里的属性值要是String,那就对不上这个值,会报错

org.springframework.beans.InvalidPropertyException: Invalid property 'vitNeedreply[]' of bean class [com.ces.petition.query.RoleAccessQuery]: Property referenced in indexed property path 'vitNeedreply[]' is neither an array nor a List nor a Map; returned value was [001]

所以这是不正确的,正确做法是:

$("#vitNeedreply option:selected").val();

这样才能取得一个值