<select id="selectId">
<option value="orange">橙色</option>
<option value="yellow">黄色</option>
</select>
1、通过value值设置
$("#selectId").val("yellow");
2、通过prop设置
$("#selectId option[value='yellow']").prop("selected",true);
$("#selectId option[value='yellow']").prop("selected","selected");
3、通过循环遍历匹配
//通过循环遍历匹配text
var color = "黄色";
$("#selectId").find("option").each(function(){
if($(this).text() == color) {
$(this).attr("selected",true);
}
});
//通过遍历匹配value
var color = "yellow";
$("#selectId").find("option").each(function(){
if($(this).val() == color) {
$(this).attr("selected",true);
}
});