How to change textbox value on select event with autocomplete (jQuery UI)

前端 未结 5 1867
一生所求
一生所求 2021-02-07 06:23

Why won\'t #input-myBox clear when I select an item? It seems autocomplete is preventing my .val(\'\') to work so how can I workaround this?

         


        
5条回答
  •  梦毁少年i
    2021-02-07 06:58

    event.preventDefault() stops autocomplete setting the field.

    select: function (event, ui) {
      event.preventDefault();
      var selectedObj = ui.item;
      $("#input-myBox").appendTo(".foo");
      $("#input-myBox").val('');  
    }
    

提交回复
热议问题