x
1
<p>该实例演示了如何使用 HTML DOM 向 input 元素添加 "onsearch" 事件。</p>
2
<p>在搜索文本域中输入信息并按下 "ENTER" 键。</p>
3
<input type="search" id="myInput">
4
<p><strong>注意:</strong>Internet Explorer, Firefox 或 Opera 12 及其更早版本不支持 onsearch 事件。</p>
5
<p id="demo"></p>
6
<script>
7
document.getElementById("myInput").onsearch = function() {
8
myFunction()
9
};
10
11
function myFunction() {
12
var x = document.getElementById("myInput");
13
document.getElementById("demo").innerHTML = "您搜索的内容为:" + x.value;
14
}
15
</script>