onsearch 事件對于搜索很有用,即用戶在輸入元素中按 ENTER 或“x”鍵。 的類型是search,因?yàn)樗枪┯脩羲阉鞯摹?Internet Explorer、Firefox 和 Opera 不支持 onsearch 事件。
示例
您可以嘗試運(yùn)行以下代碼來了解如何在 JavaScript 中實(shí)現(xiàn) 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>
登錄后復(fù)制
以上就是在JavaScript中,onsearch事件的用法是什么?的詳細(xì)內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!






