<script src="jquery.js" language="javascript"></script>
<span id="xx">广州市</span>
<select id="select_id">
<option>北京市</option>
<option>广州市</option>
<option>上海市</option>
</select>
如何让select 选中 广州市 ?
上面的都已经经过IE8。FIFIREFOX 测试都正常
<span id="xx">广州市</span>
<select id="select_id">
<option>北京市</option>
<option>广州市</option>
<option>上海市</option>
</select>
如何让select 选中 广州市 ?
百度上搜到 $("#select_id option[text='广州市']").attr("selected", true); 但用不了><!!!
<script>
//普通js写法
document.getElementById(
"select_id"
).options[1].setAttribute(
"selected"
,
true
);
//jquery应该这样写
$(
"#select_id option"
).eq(1).attr(
"selected"
,
true
);
</script>
<html>
<body>
<select id=
"selectedId"
>
<option value=
"1"
>天津</option>
<option value=
"2"
> 北京</option>
<option value=
"3"
>上海</option>
</select>
</body>
<script src=
"jquery.js"
type=
"text/javascript"
></script>
<script>
// $("#selectedId").val("3");
$(
"#selectedId"
).find(
"option"
).eq(2).attr(
"selected"
,
"selected"
)
</script>
</html>
上面的都已经经过IE8。FIFIREFOX 测试都正常