怎么让select下的option选中

  
这里以默认选中性别为例:
HTML文件:
<select name="sex" id="sex">
    <option value="1"></option>
    <option value="2"></option>
</select>
 jQuery方法
$(function(){
    $("#sex").find("option[value = '"++"']").attr("selected","selected");
})
$("#sex").find("option:contains('男')").attr("selected", true); 亲测可用
 JS方法:
function fun(){
    document.getElementById("sex").value = 2;
}
 
相关文章