按Enter键不会搜索 [英] Pressing enter key doesn't search

查看:203
本文介绍了按Enter键不会搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索事件不是通过Enter键触发的,但是如果手动按下搜索"按钮,则可以正常运行. 这是我的简单脚本

Searching event isn't triggered with enter key but works fine if manually press Search button. Here's my simple script

$('#searchproductbrand').live('click',function() {
    var search = $('.searchproductbrand').val();
    window.open('search.php?search='+search,'_self');
});

$('.searchproductbrand').keypress(function(e) {
if (e.which == 13) {
var search = $('.searchproductbrand').val();
window.open('search.php?search='+search,'_self');
}
});

这是我的文本框&按钮.

And here is my textbox & button.

<input type="search" id="text" class="searchproductbrand" placeholder="Search for Product, Brand" onkeyup="showResult(this.value)" autofocus="autofocus" />
<input type="button" id="searchproductbrand" class="button" value="Search" style="padding: 10px 10px;"/>

因此,按按钮可以正常工作,但在搜索时按Enter键不起作用.有人可以帮忙吗?

So pressing button works fine but pressing enter key while searching doesn't work. Anyone can help?

推荐答案

您是否尝试过live("keypress")吗?

Have you tried live("keypress") ?

这篇关于按Enter键不会搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆