jquery Simulation Press ENTER to implement code _jquery

Source: Internet
Author: User
Simply write down jquery to implement the carriage return event with the following code:
Global:
Copy Code code as follows:

$ (function () {
Document.onkeydown = function (e) {
var ev = document.all? Window.event:e;
if (ev.keycode==13) {
$ (' #FormId). Submit ()//handle Event
}
}
});

A control:
Copy Code code 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

If you want to simulate the TAB key, just write as if (window.event.keycode==13) window.event.keycode=9 and it jumps to another element.

It is well known that in the pagination of Easyui to jump to a page, just enter the page number to press ENTER to achieve the effect. Some time ago the project customer requests that wants to enter the page number presses a Go button to do jumps. Well, the client is God and what they say about us these programs apes can only do their best to achieve results. As shown in figure:

That is: press go to do input 3 the same thing as press ENTER

And this problem can be simplified to click a A-tag analog pagination page number input box to press ENTER but this event is written in Jquery.easyui.min.js, we have no way to call directly; through the chrome query to the page Number entry box is

Copy Code code as follows:

<input class= "Pagination-num" type= "text" value= "1" size= "2" >

Then we looked at the event object of the jquery API and found that jquery has a trigger method that triggers the simulated keystroke events. Directly on the code
Copy Code code as follows:

<script language= "javascript" type= "Text/javascript" >
$ (document). Ready (function () {
$ ("#test"). DataGrid ({
URL: "/test/test1data",
Type: "Post",
DataType: "JSON",
width:465,
height:280,
Loadmsg: "In data loading, please later ...",
Fitcloumns:true,
Nowrap:true,
Rownumbers:false,
Pagination:true,
Singleselect:true,
Showfooter:true,
Columns: [[
{field: ' TestName ', title: ' Test Name ', width:230, Editor: ' Text '},
{field: ' TestValue ', title: ' Test value ', width:230,align: ' Center '}
]]
});
$ ("#test"). DataGrid (' Getpager '). Pagination ({
Showpagelist:false,
Showrefresh:false,
Beforepagetext: "The first",
Afterpagetext: "Page <a href= ' javascript:void (0) ' onclick= ' goenterpage () ' ></a>, total {pages} page ',
Displaymsg: ' Current {from} to {to} ', all {total} bar '
});
}); The above code parameters can refer to Easyui's documentation
function Goenterpage () {
var e = jquery.event ("KeyDown");//Simulate a keyboard event
E.keycode = 13;//keycode=13 is a carriage return
$ ("Input.pagination-num"). Trigger (E);//Simulate Page number box press ENTER
}
</script>

Easyui Official website: http://www.jeasyui.com/index.php
jquery:http://jquery.com/
Here's a Chinese manual for jquery, which explains it all: http://jquery.org.cn/manual/

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.