WD1X.COM - 问答一下,轻松解决,电脑应用解决专家
主板显卡CPU内存显示器
硬盘维修显卡维修显示器维修
注册表系统命令DOS命令Win8
存储光存储鼠标键盘
内存维修打印机维修
WinXPWin7Win11Linux
硬件综合机箱电源散热器手机数码
主板维修CPU维修键盘鼠标维修
Word教程Excel教程PowerPointWPS
网络工具系统工具图像工具
数据库javascript服务器
PHP教程CSS教程XML教程

JavaScript搜索框响应事件

更新时间:2021-05-13 09:27 作者:佚名点击:

HTML页面,注意:不要使用form标签

1
2
3
<input type = "text" name="keyword" id="keyword"  onkeydown="entersearch()"/> 
<input type = "text" name="keyword" id="keyword"  onkeydown="entersearch1(event)"/> 
<input type = "button" onclick="search()"/> 

 

 

1<input type = "text" name="keyword" id="keyword"  onkeydown="entersearch()"/>
2<input type = "text" name="keyword" id="keyword"  onkeydown="entersearch1(event)"/>
3<input type = "button" onclick="search()"/>

Javascript实现方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// onclick事件 
function search(){ 
    var $keyword = $("#keyword").val(); 
    window.location.href = "/list-0-0-0-0-"+$keyword+"-0-0-1.html"
  
// 按Enter键,执行事件 
function entersearch(){ 
    var event = window.event || arguments.callee.caller.arguments[0]; 
    if (event.keyCode == 13) 
       
          search(); 
       
  
// 按Enter键,执行事件 
function entersearch1(event){ 
    if (event.keyCode == 13) 
       
          search(); 
       

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
你可能感兴趣的内容