当用户在HTML的搜索字段中写入内容时执行脚本?
当用户在搜索字段中写入内容并按Enter或x时,请使用HTML中的onsearch属性执行脚本。
示例
您可以尝试运行以下代码以实现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>热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志