Home  >  Article  >  Web Front-end  >  JavaScript creates new tags, determines keyboard input, and determines focus (sample code)_javascript skills

JavaScript creates new tags, determines keyboard input, and determines focus (sample code)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:12:37935browse

As shown below:

Copy the code The code is as follows:

function saomiao(event,n)
{
     var code=0;
     code=event.keyCode;//监听键盘输入事件
     if(code=='13')//如果键盘输入回车键
     {
          if(n>0)//开始判断参数
          {
               if(document.getElementById('logisticsno').value=='')
          {
           alert('请扫描输入运单号!');
                     var r=document.getElementById('logisticsno');
                     r.focus();
           return false;
                   }
             else if(document.activeElement.name!='deliver_money')//document.activeElement.name焦点所在的元素名
             {
                     var r=document.getElementById('deliver_money');
                     r.focus();       
               }
             else//如果所有条件都满足
             {
                 var r=document.getElementById('logisticsno');
                     r.focus();
                     var f=document.createElement('form');//开始新建表单
                     f.action='/modules/logistics/start.php';
                     document.body.appendChild(f);//添加至body

                     var e=document.createElement('input');//新建表单元素
                     e.type='hidden';
                     e.name='act';
                     e.id='act';
                     e.value='logisticsno';
                     f.appendChild(e);//添加至表单

                     var data_id=0;
                     var g=document.getElementsByName("orderdataid_no[]");
                     var h=0;
                     for(var h=0;h {
data_id=g[h].value;
}

                     var order_no=0;
                     var gg=document.getElementsByName("order_no[]");
                     var hh=0;
                     for(var hh=0;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();//表单提交
                   }  
               }   
      }
     }
//开始监控键盘输入

 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn