Javascript creates new tags determines keyboard input and determines the focus of sample code

  • 2020-03-29 23:57:22
  • OfStack

As follows:


function saomiao(event,n)
{
     var code=0;
     code=event.keyCode;//Listen for keyboard input events
     if(code=='13')//If the keyboard enters the enter key
     {
          if(n>0)//Start parameter
          {
               if(document.getElementById('logisticsno').value=='')
          {
           alert(' Please scan and enter the waybill number !');
                     var r=document.getElementById('logisticsno');
                     r.focus();
           return false;
                   }
             else if(document.activeElement.name!='deliver_money')//Document. ActiveElement. Name focus element name
             {
                     var r=document.getElementById('deliver_money');
                     r.focus();        
               }
             else//If all the conditions are met
             {
                 var r=document.getElementById('logisticsno');
                     r.focus();
                     var f=document.createElement('form');//So let's start a new form
                     f.action='/modules/logistics/start.php';
                     document.body.appendChild(f);//Added to the body

                     var e=document.createElement('input');//New form element
                     e.type='hidden';
                     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='hidden';
                     k.name='order_no';
                     k.id='order_no';
                     k.value=order_no;
                     f.appendChild(k);

                     f.submit();//The form submission
                   }   
               }    
      }
     }
<body onKeyPress="javascript:saomiao(event,555);">//Start monitoring keyboard input
 


Related articles: