Saturday 27 April 2019

javascript - How can I trigger onclick function when I press enter button?




I use the code below to update the url link based on user text input:










Right now it works pretty fine when someone clicks the submit button. What I want is to make it also work when a user press the enter button. Fiddle HERE


Answer



Try with this:



$(document).keypress(function(e) {
if(e.which == 13) {

var url = "/tag/";
url += $('#q').val();
window.location = url;
}
});

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...