繁体   English   中英

VB.NET:在文本框中按Enter时如何执行jquery代码

[英]VB.NET: How to execute jquery code when pressing enter in textbox

我有一个问题,我试图从文本框中执行搜索查询,并尝试使用Enter启动搜索; 但是,它似乎不起作用。 我想知道vb.net/asp.net是否正在执行回发或我不知道的事情。

ASPX页面

 <form class="navbar-search">
     <input id="searchbox" type="text" class="search-query span3" placeholder="Search" />
     <div class="icon-search"></div>
 </form>

JQuery的

$('#searchbox').keyup(function (e) {
    //alert("this will execute");
    if (e.which == 13) {
        alert("this will not execute");
        //window.location.href = "http://www.google.com/";
    }
});

如果有人可以帮助我,我将无法执行警报框或更改位置工作。

尝试这个:

$("#searchbox").keypress(function (e) {
    //alert("this will execute");
    var code = e.keyCode || e.which;
    if (code == 13) {
        alert("this will not execute");
        //window.location.href = "http://www.google.com/";
    }
});

并要阻止页面刷新进入,请使用以下命令:

$(document).keydown(function (e) {
    var code = e.keyCode || e.which;
    if (code === 13) {
        e.preventDefault();
    }
});

小提琴

请尝试这个。

$("#searchbox").live("keyup", function(event) {
        if (event.keyCode == 13) {
            //window.location.href = "http://www.google.com/";
        }
    });

这对我有用...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM