编辑下面的代码:【加编码】
<html> <body> <p>该实例演示了如何使用 HTML DOM 向 input 元素添加 "onsearch" 事件。</p> <p>在搜索文本域中输入信息并按下 "ENTER" 键。</p> <input type="search" id="myInput"> <p><strong>注意:</strong>Internet Explorer, Firefox 或 Opera 12 及其更早版本不支持 onsearch 事件。</p> <p id="demo"></p> <script> document.getElementById("myInput").onsearch = function() {myFunction()}; function myFunction() { var x = document.getElementById("myInput"); document.getElementById("demo").innerHTML = "您搜索的内容为:" + x.value; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂