當用戶在 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