Trigger the event when selected the same value in dropdown?

后端 未结 5 614
予麋鹿
予麋鹿 2021-01-14 18:52

Issue: I have a dropdown with a list of years in it with nothing selected, the user selects \"1976\", I run a function. If the user clicks on the dropdown again and selects

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-14 19:27

    The closest functionality that you're seeking that I can think of is the following:

    -HTML-

    
    

    -jQuery-

    $(document).ready(function(){
    
        $('.opt-evt').change(function(){
            $(this).blur();
        }).blur(function(){
            console.log($(this).find('option:selected').val());
        });
    
    });
    

    The caveat is that if the user selects '1976' again, the desired event only gets fired onBlur.

    http://jsfiddle.net/4G9Jf/

提交回复
热议问题