使用搜索栏并反跳

问题描述 投票:0回答:1

我已经正确创建了一个实现反跳的搜索栏。我创建了一个jQuery输入字段,调用了handleHandKeyKeyPress函数。该函数通过调用event.target.value来获取当前值,并使用该值来调用另一个“去抖动”函数。然后,此反跳功能将一个函数和timeDelay作为参数,并实现清除当前超时值并设置一个新的一般反跳模式。然后,此函数(前提是它超过了timeDelay),然后使用传入的值进行其他处理。我遇到的问题是搜索栏。当我输入“你好,世界!”然后等待500毫秒,它使用字符串“ Hello,world”,最后一个字符丢失。这是一些代码:

//This function is called and the returned value is rendered into the page
export const renderNavBar = function() {
let searchBar = $('<input type="text" placeholder="Search for player here...">').keydown(handleSearchKeyPress);
let panel = $('<div></div>').append(searchBar);
return panel;
}

export const handleSearchKeyPress = function() {
let value = event.target.value;
console.log(value);
}

如果我键入“ hi”,则上面控制的值将返回“ h”。谁能解释为什么以及如何让“ hi”出现?

uisearchbar debouncing
1个回答
0
投票

更新:我只需要使用keyup功能。 keydown函数会在释放键之前调用现有的小节,因此不包含我打算包含的字母。

© www.soinside.com 2019 - 2024. All rights reserved.