jQuery绑定键盘事件

作者:lina791211-----感谢作者!!

雪影工作室版权所有,转载请注明【http://blog.csdn.net/lina791211】


1、前言

        Jquery绑定各种键盘输入事件。

  键值获取http://blog.csdn.net/lina791211/article/details/36025571 


2、绑定回车键

        input输入框绑定回车响应(提交数据)

<span> 
<pre name="code" class="html" style="font-size: 18px; line-height: 26px;"><span style="font-family: Arial;"></span><pre name="code" class="html" style="font-size: 18px; line-height: 26px;">	<span style="font-family: Arial;"><input class="typeahead" type="text" id="textfield" placeholder="请输入搜索关键词" style="margin-top: 10px;width: 410px"></span>

 
</span> 
 

<span>
	<button type="button" class="btn_search btn_search_primary" id="simpleSearchButton"  style="top:0;margin-top: -3px">搜   索</button>
</span>


        /*监听输入框的回车操作*/
        $('#keyword').bind('keypress',function(event){
            if(event.keyCode == "13") $('#simpleSearchButton').click();
        });

3、button绑定click事件并提交数据

        

		$('#simpleSearchButton').click(function(){
			var _k = $('#textfield').val();
			var url = '';
			if(_k==null || _k==""){
				//url = encodeURI('<%=path%>/');
				return;
			}else{
				url = encodeURI('<%=path%>/search.jsp?keyword=' + _k);
			}
			
			url = encodeURI(url);
			window.open(url,'_self');
		});

4、页面绑定键盘左键、右键进行翻页

 

<div id="search_paging">
	<div class="gigantic pagination">
	    <a href="#" class="first" data-action="first">«</a>
	    <a href="#" class="previous" data-action="previous">‹</a>
	    <input class='current' id='c_page' type="text"  value="Page 10 of 10"/>
	    <a href="#" class="next" data-action="next">›</a>
	    <a href="#" class="last" data-action="last">»</a>
	</div>
</div>

   
        /*监听键盘上左右键的点击*/
		$(document).keydown(function(event){
	    <span style="white-space:pre">		</span>if(event.which == "37") {	$(".previous").click(); return;}
            <span style="white-space:pre">		</span>if(event.which == "39") {	$(".next").click(); return;}
		});


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值