Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.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
当搜索表单更改时,如何在typescript中打印内容?_Typescript - Fatal编程技术网

当搜索表单更改时,如何在typescript中打印内容?

当搜索表单更改时,如何在typescript中打印内容?,typescript,Typescript,这是我的html文件: <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <input type="search" id

这是我的html文件:

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
    <body>
        <input type="search" id="site-search" name="q"
       aria-label="Search through site content" onchange="onChange()">
    <script id="search_js" src="compiled/search.js"></script>
</body>
</html>
每当在搜索字段中键入内容时,我想在我的typescript代码中使用onChange函数

下面是一个示例代码笔演示:


关于

您将注意到,在您完成编辑文本框并移除焦点后,
onchange
事件将被触发

要在用户编辑文本框时运行回调,可以监听
元素的
onkeup
事件,该事件将在文本框中的每次按键时触发

  const search : HTMLElement | null  = document.getElementById("site-search");
  function onChange(event: any) {
    search.innerText = "toto";
    search.textContent = "toto";
    console.log("titi");

  }
console.log("toto);