当用户在 HTML 中的搜索字段中输入内容后执行脚本?
在 HTML 中使用 onsearch 属性,以便当用户在搜索字段中输入内容并按 ENTER 或 x 时执行脚本。
实例
你可以尝试运行以下代码以实现 onsearch 属性:
<!DOCTYPE html>
<html>
<body>
<p>Search something and press ENTER.</p>
<input type = "search" id="inputID" onsearch = "display()">
<p><strong>Note:</strong> It won' work in Internet Explorer and Firefox.</p>
<p id="test"></p>
<script>
function display() {
var a = document.getElementById("inputID");
document.getElementById("test").innerHTML = "Searched for - " + a.value;
}
</script>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP