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

前端 未结 5 1865
一生所求
一生所求 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条回答
  • 2021-02-07 06:46

    Also, you can use 'return false;' to stop autocomplete setting the field.

    select: function (event, ui) { 
        var selectedObj = ui.item;        
        $("#input-myBox").appendTo(".foo");
        $("#input-myBox").val('');  
        return false;
    }
    
    0 讨论(0)
  • 2021-02-07 06:47

    There is inconsistent with your code:

    $("#input-mybox").appendTo(".foo");
    $("#input-myBox").val('');  
    

    "#input-myBox" || "#input-mybox" ???

    0 讨论(0)
  • 2021-02-07 06:52

    If you just want to substitute the selected value for something else:

    select: function( event, ui ) {
      ui.item.value = substituteWord(ui.item.value);
    }
    
    0 讨论(0)
  • 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('');  
    }
    
    0 讨论(0)
  • 2021-02-07 07:08

    Is it #input-mybox (lowercase b) or #input-myBox (uppercase b) ?

    This might be your problem :)

    Edit: rob beat me to it

    0 讨论(0)
提交回复
热议问题