How do I get the change event for a datalist?

前端 未结 6 687
轮回少年
轮回少年 2021-02-05 11:14

I am using a datalist and need to detect when the user selects something from the drop-down list. A similar question has been asked BUT I need it so that the event fires ONLY wh

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-05 11:59

    Optimized Solution

    $("input").on('input', function () {
        var inputValue = this.value;
        if($('datalist').find('option').filter(function(){
            return this.value == inputVal;        
        }).length) {
            //your code as per need
            alert(this.value);
        }
    });
    

提交回复
热议问题