开发者

Please help with prependTo & replace javascript code!

开发者 https://www.devze.com 2023-02-17 13:52 出处:网络
<script type=\"text/javascript\"> $(document).ready(function() { $(\'#divID\').each(function() { var $select = $(\'<select id=\"dropdown\" onchange=\"location = this.options[this.selectedInde
<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');
0

精彩评论

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