//jquery选中select function selectByValue(sltName,value){ $("select[@name="+sltName+"] option").each(function(){ if($(this).val() == value){ $(this).attr("selected","selected"); } }); } //更直接: $("#sltName").val(data.topicVoteBean.maxCount);
取值:
【引自:http://zhangyulong.iteye.com/blog/1328615】
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(); 这样就去到了