jquery select option 设置selected属性
//jquery选中selectfunction selectByValue(sltName,value){ $("select[@name="+sltName+"] option").each(function(){ if($(this).val() == value){ $(this).attr("selected","selected"); } }); } //更直接:$("#sltName").val(data.topicVoteBean.maxCount);
var sex = $("#search_form select[name='sex'] option:selected ").attr("value");var sex = $("#search_form select[name=sex'] option[selected]").attr("value");这样写会有问题 sex的值有时是undifined 改为var sex = $("#search_form select[name='sex'] option:selected ").attr("value");var val = $("#search_form select[name='sex']").children('option:selected').val();这样就去到了