<select id="selectExample"> <option value="1">aaa</option> <option value="2">bbb</option> <option value="3">ccc</option> </select>
- 根据value值设置默认选中
//方法一: $("#selectExample").val('1');//设置value为1的option选项为默认选中 //方法二: $("#selectExample option[value='1']").prop("selected",true); //方法三: $("#selectExample option[value='1']").prop("selected",selected);
- 根据text值设置默认选中
var selected="上海"; $("#selectExample").find("option").each(function(){ if($(this).text() == selected) { $(this).attr("selected",true); } });
多选框默认选中
$("#sel").val(Array('1','2'));//设置value=1和2的选项为默认选中