jquery select item by contains 1.10.2

时间:2014-01-04 20:54:29

标签: jquery

这与jquery 1.4.4有关,但我需要1.10.2,谢谢你的回复!

<select id="region_id" name="region_id" class="control-self control-self-select m_js_region">
    <option>Chose region</option>
    <option>Moscow</option>
    <option>Saint-Petersburg</option>
</select>
$("#region_id :contains('Moscow')").attr("selected", "selected");

2 个答案:

答案 0 :(得分:2)

尝试

$("#region_id :contains('Moscow')").prop("selected", "selected");

答案 1 :(得分:1)

改为使用prop()

$("#region_id :contains('Moscow')").prop("selected", true);