JavaScript 中 onsearch 事件的用法是什麼?
onsearch 事件對於搜尋來說很有用,即使用者在輸入元素中按 ENTER 或 “x” 鍵。<input> 型別是搜尋,因為它供使用者搜尋使用。在 Internet Explorer、Firefox 和 Opera 中不支援 onsearch 事件。
示例
你可以嘗試執行以下程式碼來了解如何在 JavaScript 中實現 onsearch 事件。
<!DOCTYPE html>
<html>
<body>
<p>Write what you want to search below and press "ENTER".</p>
<input type = "search" id = "newInput" onsearch = "searchFunc()">
<script>
function searchFunc() {
var a = document.getElementById("newInput");
document.write("Searched = " + a.value);
}
</script>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP