下面是我的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>这是我的search.ts文件:
const search : HTMLElement | null = document.getElementById("site-search");
function onChange(event: any) {
search.innerText = "toto";
search.textContent = "toto";
console.log("titi");
}
console.log("toto);每当在搜索字段中键入内容时,我希望在我的typescript代码中使用函数onChange。
下面是一个示例代码演示:
https://codepen.io/bussiere/pen/vYgjaej
问候
发布于 2021-04-15 02:59:31
您将在代码链接中注意到,当您完成编辑文本框并移除焦点时,将触发onchange事件。
要在用户编辑文本框时运行回调,可以侦听<input />元素的onkeup事件,该事件将在文本框中的每一次击键时触发。
https://stackoverflow.com/questions/67097509
复制相似问题