gpt4 book ai didi

javascript - 在用户仍在输入时异步获取输入值

转载 作者:行者123 更新时间:2023-11-29 20:27:58 25 4
gpt4 key购买 nike

我有一个这样的输入框

 <input type="text" placeholder="Search" id="search" />

并希望在用户仍在键入时读取内容,然后在搜索字符串匹配时显示数据。我想我需要一个异步函数,但我不知道如何继续处理字符串。

async function readSearchString(){
return document.getElementById("search").value;
}


function processString(cell, string)
{
// Keep doing this
var searchString = await readSearchString();
if (cell.includes(searchString))
{
cell.visibility = "hidden";
}
}

我是否需要以某种方式无限循环地运行整个函数以不断获取用户输入?

最佳答案

您可以根据需要使用onchangeonkeyuponkeydown 等输入事件。

function processString()
{
var searchString = document.getElementById("search").value;
console.log('Search key :'+ searchString);
// You can do your search code here
/*
if (cell.includes(searchString))
{
cell.visibility = "hidden";
}
*/
}
<input type="text" placeholder="Search" id="search"  onkeyup="processString()">

关于javascript - 在用户仍在输入时异步获取输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58875499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com