Please help with prependTo & replace javascript code!
<script type="text/javascript">
$(document).ready(function() {
$('#divID').each(function() {
var $select = $('<select id="dropdown" onchange="location = this.options[this.selectedIndex].value;" />');
$(this).find('a').each(function() {
var $option = $('<option />');
$option.attr('value', $(this).attr('href')).html($(this).html());
$select.append($option);
});
开发者_StackOverflow中文版 $(this).replaceWith($select);
});
$('<option selected="selected" value="#">Select Option</option>').prependTo('#dropdown');
});
</script>
Everything works great EXCEPT the prepended option selected="selected" doesn't work in IE.
try this
$('<option value="#">Select Option</option>').attr('selected', 'selected').prependTo('#dropdown');
精彩评论