简体   繁体   中英

Jquery trigger on keypress call function

my question is about :

i want to trigger this function on enter click

$('.s-link').click(function()
{
    var x = "/search/node?keys=";
    var y = $('.i-search').val();
    var result = x + y;
    $('a').attr('href', result);

});

You can put code inside onclick

$(document).keypress(function(e) {
if(e.which == 13) {
    alert('You pressed enter!');
    var x = "/search/node?keys=";
var y = $('.i-search').val();
var result = x + y;
$('a').attr('href', result);
}
});
$('#someTextBox').keypress(function(event){
    var keycode = (event.keyCode ? event.keyCode : event.which);
    if(keycode == '13'){
       var x = "/search/node?keys=";
       var y = $('.i-search').val();
       var result = x + y;
      $('a').attr('href', result);

    }
});

try this and change #someTextBox according to your program

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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