Recently I am working on a Web project. I use a third-party control of DevExpress.
Because the control has few skills in Chinese, it is really awkward. It can only be explored and developed.
Today, I want to implement some editing boxes such as ASPxTextBox, ASPxComboBox, and other controls to press enter to simulate the Tab function. This is no way. You are used to press the carriage return and hate to press the Tab to move the focus (it is more troublesome to click the mouse ).
Taking ASPxTextBox as an example, many client JavaScript code can be set in the ClientSideEvents attribute, where KeyPress is what I want to write.
First, you have to prepare the JS Code to simulate the Tab. There are a lot of code on the Internet. I 'd like to try it and paste it as follows:
Copy codeThe Code is as follows:
// Press the Enter key to simulate the tab in onkeydown.
Function EnterAsTab ()
{
Var el_keydown = window. event. srcElement;
Var len;
If (window. event. keyCode = 13 & el_keydown.type! = "Textarea ")
| (Window. event. keyCode = 13 & window. event. ctrlKey & el_keydown.type = "textarea "))
{
Len = document. forms (0). length;
For (var I = 0; I <len; I ++)
{
If (document. forms (0). elements (I) = el_keydown)
{
// Skip the hidden and disabled input boxes
// If the next control is a button, skip the next control until it is not a button or has no control.
Do
{
I ++;
If (I> = len)
Return;
}
While (document. forms (0). elements (I). disabled | document. forms (0). elements (I). type = 'den den'
| Document. forms (0). elements (I). type = 'click'
| Document. forms (0). elements (I). type = 'submit'
| Document. forms (0). elements (I). type = 'reset'
| Document. forms (0). elements (I). type = 'href '));
// Alert ('object '+ I +' type: '+ document. forms (0). elements (I). type );
Document. forms (0). elements (I). focus ();
Document. forms (0). elements (I). select ();
Event. returnValue = false; // discard the excessive carriage return. Otherwise, the enter textarea and button will directly send the carriage return!
Return;
}
}
}
}
Then, the KeyPress Event code is inserted into the HTML code of the ASPxEditBox control.
Copy codeThe Code is as follows:
<Dxe: ASPxTextBox ID = "txtCodeName" runat = "server" Width = "170px"
Text = '<% # Bind ("CodeName") %>'>
<ClientSideEvents KeyPress = "function (s, e) {var key = event. keyCode;
If (key = 13) {EnterAsTab () ;}} "/>
</Dxe: ASPxTextBox>
Obtain the key value event. keyCode and assign it to the key. Then judge whether the key value is equal to 13 (enter key). If yes, call the previous JS function EnterAsTab ().
Other controls are similar.