Firefox not refreshing select tag on page refresh

后端 未结 3 912
梦如初夏
梦如初夏 2020-12-19 12:26

I\'ve run into a problem where I have a select tag that the user would use to select a brand of phone and the page using jquery would then just display those phones.

<
3条回答
  •  隐瞒了意图╮
    2020-12-19 13:05

    I think I have more simple solution. Why not to set the select back to index 0 when document is ready? It could look like this:

    $('.manufacturers').prop('selectedIndex',0);
    

    So your script could look like this:

    $(document).ready(function() {
    
        $('.manufacturers').prop('selectedIndex',0);
    
        $('.manufacturers').change(function() {
            var selected = $(this).find(':selected');
            $('ul.manulist').hide();
            if ($(this).val() == 'all') {
                $('.scroll-content ul').show();
            } else {
                $('.' + selected.val()).show();
                $('.optionvalue').html(selected.html()).attr(
                        'class', 'optionvalue ' + selected.val());
            }
        });
    });
    

    And after reload the select will be back to the first position.

提交回复
热议问题