开发者

jQuery first option selected on backbutton in IE

开发者 https://www.devze.com 2023-03-24 12:02 出处:网络
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:

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

精彩评论

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