当搜索表单更改时,如何在typescript中打印内容?
这是我的html文件:当搜索表单更改时,如何在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
<!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);