javascript新建标签,判断键盘输入,以及判断焦点(示例代码)


如下所示:

复制代码 代码如下:

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<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();//表单提交
                   }  
               }   
      }
     }
<body onKeyPress="javascript:saomiao(event,555);">//开始监控键盘输入

 


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3