jQuery get value of select onChange

后端 未结 16 1793
星月不相逢
星月不相逢 2020-11-22 05:31

I was under the impression that I could get the value of a select input by doing this $(this).val(); and applying the onchange parameter to the sel

16条回答
  •  滥情空心
    2020-11-22 05:45

    Note that if these are not working, it might be because the DOM has not loaded and your element was not found yet.

    To fix, put the script at the end of body or use document ready

    $.ready(function() {
        $("select").on('change', function(ret) {  
             console.log(ret.target.value)
        }
    })
    

提交回复
热议问题