Create a tag in javascript, judge the keyboard input, and determine the focus (sample code)

Source: Internet
Author: User

As follows:
Copy codeThe Code is as follows:
Function saomiao (event, n)
{
Var code = 0;
Code = event. keyCode; // listen to keyboard input events
If (code = '13') // if you enter the Enter key on the keyboard
{
If (n> 0) // starts to judge the Parameter
{
If (document. getElementById ('logisticsno'). value = '')
{
Alert ('Scan and enter the waybill number! ');
Var r = document. getElementById ('logisticsno ');
R. focus ();
Return false;
}
Else if (document. activeElement. name! = 'Deliver _ money') // name of the element in which document. activeElement. name focuses
{
Var r = document. getElementById ('Deliver _ money ');
R. focus ();
}
Else // if all conditions are met
{
Var r = document. getElementById ('logisticsno ');
R. focus ();
Var f = document. createElement ('form'); // start creating a form
F. action = '/modules/logistics/start. php ';
Document. body. appendChild (f); // Add to body

Var e = document. createElement ('input'); // create a form Element
E. type = 'ddn ';
E. name = 'act ';
E. id = 'act ';
E. value = 'logisticsno ';
F. appendChild (e); // Add to form

Var data_id = 0;
Var g = document. getElementsByName ("orderdataid_no []");
Var h = 0;
For (var h = 0; h <g. length; h ++)
{
Data_id = g [h]. value;
}

Var order_no = 0;
Var gg = document. getElementsByName ("order_no []");
Var hh = 0;
For (var hh = 0; hh <gg. length; hh ++)
{
Order_no = gg [hh]. value;
}

Var k = document. createElement ('input ');
K. type = 'ddn ';
K. name = 'order _ no ';
K. id = 'order _ no ';
K. value = order_no;
F. appendChild (k );

F. submit (); // form submission
}
}
}
}
<Body onKeyPress = "javascript: saomiao (event, 555);"> // start monitoring keyboard input
 

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.