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;
精彩评论