开发者

jQuery first option selected on backbutton in IE

I have a select box, and when someone hits the back button, I'd like the first option to be selected again. It works f开发者_高级运维ine in Chrome and such, but not IE 8. Here's my code:

<select id="select-city">
   <option selected="selected">Choose city</option>
   <option value="Acton-Vale">Acton Vale</option>
   <option value="Alma">Alma</option>
   <option value="Amos">Amos</option>
</select>


<script type="text/javascript">
  $('#select-city')[0].selectedIndex = 0;
</script>

Any ideas?


Try putting your JavaScript in a document ready block

$(document).ready(function() {
  ...
});


var select = $('#select-city>option');
select[1].selected = true;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜