首页  >  文章  >  web前端  >  javascript新建标签,判断键盘输入,以及判断焦点(示例代码)_javascript技巧

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

WBOY
WBOY原创
2016-05-16 17:12:37939浏览

如下所示:

复制代码 代码如下:

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();//表单提交
                   }  
               }   
      }
     }
//开始监控键盘输入

 
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn