How to reset a select element with jQuery

后端 未结 15 1846
清歌不尽
清歌不尽 2020-12-24 10:37

I have


                        
    
提交评论

  • 2020-12-24 11:18

    This works a little differently from other answers in that it unselects all options:

    $("#baba option").prop("selected", false);
    

    (Borrowed from https://stackoverflow.com/a/11098981/1048376)

    0 讨论(0)
  • 2020-12-24 11:19
    $('#baba option:first').prop('selected',true);
    

    Nowadays you best use .prop(): http://api.jquery.com/prop/

    0 讨论(0)
  • 2020-12-24 11:20

    Try this. This will work. $('#baba').prop('selectedIndex',0);

    Check here http://jsfiddle.net/bibin_v/R4s3U/

    0 讨论(0)
  • 2020-12-24 11:20
    $('#baba option:first').attr('selected',true);
    
    0 讨论(0)
  • 2020-12-24 11:21

    If you want to reset by id

    $('select[id="baba"]').empty();
    

    If you want to reset by name


    $('select[name="baba"]').empty();
    
    0 讨论(0)
  • 提交回复
    热议问题