回车键代码 回车键 键 asp代码 回车换行 asp录入问题

bywzy 发表于 程序设计 分类,
0

asp网站多数据录入时.可用回车键代替<tab>键实现快速输入:
脚本程序如下:

显示被隐藏内容 显示被隐藏内容

<script>
document.onkeydown=function(){
var fx="";
var qx=true; //移到文本框中后是否自动全选
try{
  switch(event.keyCode){  //判断按键
  case 13:
   if(event.srcElement.tagName!="SUBMIT"){     //非TEXTAREA对象中按回车键
    fx="down";
   }
   break;
  case 40:
   if(event.srcElement.tagName=="INPUT"||event.ctrlKey){  //INPUT对象中按光标下键或在所有对象中按[ctrl]+光标下键
    fx="down";
   }
   break;
    case 39:
   if(event.srcElement.tagName=="INPUT"||event.ctrlKey){  //INPUT对象中按光标右键或在所有对象中按[ctrl]+光标下键
    fx="down";
   }
   break;
    case 37:
   if(event.srcElement.tagName=="INPUT"||event.ctrlKey){  //INPUT对象中按光标左键或在所有对象中按[ctrl]+光标下键
    fx="up";
   }
   break;
  
  case 38:
   if(event.srcElement.tagName=="INPUT"||event.ctrlKey){  //INPUT对象中按光标上键或在所有对象中按[ctrl]+光标上键
    fx="up";
   }
   break;
  default:
  }
  switch(fx){  //根据判断按键所得的fx值来执行向下或向上操作
  case "down":
   for(i=event.srcElement.sourceIndex+1;i<document.all.length;i++){
    if(((document.all(i).tagName=="INPUT")&&("text,password,checkbox,radio".indexOf(document.all(i).type)!=-1))||("Select,TEXTAREA".indexOf(document.all(i).tagName)!=-1)){
     if(!document.all(i).disabled){
      document.all(i).focus();
      if (document.all(i).tagName=="INPUT"&&qx)document.all(i).select();
      break;
     }
    }
   }
  if((i==document.all.length)&&(event.keyCode==13)){
  document.getElementsByName(document.all(event.srcElement.sourceIndex).name)[i].form.submit();
   }
   event.keyCode = 0;
   event.returnValue = false;
   break;
  case "up":
   for(i=event.srcElement.sourceIndex-1;i>-1;i–){
    if(((document.all(i).tagName=="INPUT")&&("text,password,checkbox,radio".indexOf(document.all(i).type)!=-1))||("Select,TEXTAREA".indexOf(document.all(i).tagName)!=-1)){
     if(!document.all(i).disabled){
      document.all(i).focus();
      if (document.all(i).tagName=="INPUT"&&qx)document.all(i).select();
      break;
     }
    }
   }
   event.keyCode = 0;
   event.returnValue = false;
   break;
  default:
  }
}catch(e){}
}
</script>
隐藏内容 隐藏内容
该内容已经被作者隐藏,只有会员才允许查阅 登录 | 注册


使用方法:<br>
1、回车键跳到下一个非按钮区,但在文本区中按回车键不跳;
2、光标下键↓右键→跳到下一个非按钮区,但在下拉框和文本区中按光标下键不跳;
3、光标上键↑左键←跳到上一个非按钮区,但在下拉框和文本区中按光标上键不跳;
4、会自动跳过被<b>disabled</b>的文本区。
5、在最后一个可获得焦点的对象上按回车键后可提交该对象所在的FORM表单。

« 上一篇: :下一篇 »

发表我的评论

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif