jQuery event for HTML5 datalist when item is selected or typed input match with item in the list

前端 未结 5 835
轻奢々
轻奢々 2020-12-25 11:08

I have datalist like below -



    
5条回答
  •  青春惊慌失措
    2020-12-25 11:57

    You can use input event for achieving such functionality, as below :

    $(document).ready(function() {
      $('#name').on('input', function() {
        var userText = $(this).val();
    
        $("#allNames").find("option").each(function() {
          if ($(this).val() == userText) {
            alert("Make Ajax call here.");
          }
        })
      })
    });
    
    
    
      

提交回复
热议问题