Home > Web Front-end > JS Tutorial > jquery simulates pressing enter implementation code_jquery

jquery simulates pressing enter implementation code_jquery

WBOY
Release: 2016-05-16 18:02:04
Original
1437 people have browsed it

Simply write down jquery to implement the carriage return event. The code is as follows:
Global:

Copy code The code is as follows:

$(function(){
document.onkeydown = function(e){
var ev = document.all ? window.event : e;
if(ev.keyCode== 13) {
$('#FormId).submit();//Handling events
}
}
});

A certain control:
Copy code The code is as follows:

$('#id').keydown(function(e) {
if(e.keyCode==13){
$('#FormId).submit(); //Handling events
}
});
if (window.event .keyCode==13) window.event.keyCode=0 //This will cancel the Enter key

If you want to simulate the Tab key, just write if (window.event.keyCode==13) window.event.keyCode=9 will do and it will jump to another element.

As we all know, if you want to jump to a certain page in easyui's Pagination, you only need to enter the page number and press ENTER to achieve the effect. In a project some time ago, the customer made a request and said that he wanted to enter the page number and press a GO button to jump. Well, customers are God, what do they say, we programmers can only do our best to achieve results. As shown in the picture:

                                                                                  That is: press GO to do the same thing as entering 3 and press Enter

This problem can be simplified to clicking an a tag to simulate the Pagination page number input box and pressing Enter. However, this event is written in jquery.easyui.min.js, and we have no way to call it directly; query the page number input box through chrome Yes




Then I checked the Event Object of the JQUERY API and found that jquery has a trigger method that can trigger simulated key events. Directly enter the code





easyui official website: http://www.jeasyui.com/index.php
jquery: http://jquery.com/
Here is a Chinese manual for jquery with complete instructions:
http://jquery.org.cn/manual/
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template