Jquery simulates press enter to implement code _ jquery

Source: Internet
Author: User
Today, I want to implement a carriage return event. I started to use the js method, but it didn't work. Originally, JQuery was a little different from JS, And it was much simpler than JS to simply write down jquery's implementation of carriage return events, the Code is as follows:
Global:

The Code is as follows:


$ (Function (){
Document. onkeydown = function (e ){
Var ev = document. all? Window. event: e;
If (ev. keyCode = 13 ){
$ ('# FormId). submit (); // process the event
}
}
});


A control:

The Code is as follows:


$ ('# Id'). keydown (function (e ){
If (e. keyCode = 13 ){
$ ('# FormId). submit (); // process the event
}
});
If (window. event. keyCode = 13) window. event. keyCode = 0 // then the Enter key is canceled.


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

As we all know, in Pagination of easyui, to jump to a page, you only need to ENTER the page number and press ENTER to achieve the effect. Some time ago, the project customer requested to enter the page number and press the GO button to redirect. Well, the customers are God. What do they say about us, these programmers can only do their best to achieve the results.

That is, press GO to input 3 and press Enter.

This problem can be simplified to clicking a label to simulate Pagination page number input box press enter, but this event is written in jquery. easyui. min. js, We can't directly call it; the page number input box found through chrome is

The Code is as follows:




Then, we checked the Event Object of jquery api and found that jquery has a trigger method that can trigger simulated button events. Directly Add code

The Code is as follows:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.