Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当用户键入新词时,如何使javascript自动完成重置?_Javascript_Jquery_Forms_Autocomplete_Jquery Ui Autocomplete - Fatal编程技术网

当用户键入新词时,如何使javascript自动完成重置?

当用户键入新词时,如何使javascript自动完成重置?,javascript,jquery,forms,autocomplete,jquery-ui-autocomplete,Javascript,Jquery,Forms,Autocomplete,Jquery Ui Autocomplete,我目前正在使用一个js函数,该函数为html输入字段提供自动完成功能。这很好,但是它只适用于用户给出的第一个单词。有没有办法让字符串中输入的每个单词都运行autocomplete函数 下面是函数 $(function() { $("#text-input").autocomplete({ source: ["Eastern Redbud", "Eastern White Pine", "Eastern Red ce

我目前正在使用一个js函数,该函数为html输入字段提供自动完成功能。这很好,但是它只适用于用户给出的第一个单词。有没有办法让字符串中输入的每个单词都运行autocomplete函数

下面是函数

$(function() {
  $("#text-input").autocomplete({
    source: ["Eastern Redbud", "Eastern White Pine", "Eastern Red cedar",],
    minLength: 1

  });
});

参考第一个答案,您可以使用
document.body.onkeyup
然后检查e.keyCode==32的空格

当按下空格键时,调用自动完成功能。现在,您必须在空格处拆分输入字段值,并使用最后一个元素将自动完成功能仅应用于新词

document.body.onkeyup = function(e){
  // execute when space was pressed  
  if(e.keyCode == 32){
       
    // apply the autocomplete only at the first word in the input field
let inputWords = $("#text-input").split(" ");
inputWords[inputWords.length -1].autocomplete({
    source: ["Eastern Redbud", "Eastern White Pine", "Eastern Red cedar",],
    minLength: 1

  });
    }
}
参考第一个答案,您可以使用
document.body.onkeyup
然后检查e.keyCode==32的空格

当按下空格键时,调用自动完成功能。现在,您必须在空格处拆分输入字段值,并使用最后一个元素将自动完成功能仅应用于新词

document.body.onkeyup = function(e){
  // execute when space was pressed  
  if(e.keyCode == 32){
       
    // apply the autocomplete only at the first word in the input field
let inputWords = $("#text-input").split(" ");
inputWords[inputWords.length -1].autocomplete({
    source: ["Eastern Redbud", "Eastern White Pine", "Eastern Red cedar",],
    minLength: 1

  });
    }
}

在输入更改事件
$(“输入”).change(函数(){alert(“文本已更改”);})上调用它
@Alex你能把你的答案扩展成一个例子吗?很抱歉,上面的回答不起作用,但我想我有另一个解决方案,我会在输入更改事件
$(“输入”).change(函数(){alert(“文本已更改”);})
@Alex你能把你的答案扩展成一个例子吗?很抱歉,上面的回答不起作用,但我想我有另一个解决方案,我会写一个答案