一段模拟按键查找文件的JS

很多,用户要求按下一个健后,如果以这个字母或者数字、其他字符开头的进程名称存在的话,就直接选定那个名称,于是我就用JS模拟了一个简单的查找文件的过程。把文本框放到表格中(通过CSS把文本框隐藏,并且只读),为了简单我没有放上CSS,如果需要,请自己写一个,代码如下:(非常得少,而且简单 :))  

 

 

<html>

<head>

<title>Display Processes Stat</title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<link href="style" rel="stylesheet" type="text/css">

</head>

<body leftmargin="0" topmargin="0">

<SCRIPT language=javascript>Count=0OldKey="";IfExists=false;function document.onkeypress(){ if(document.all.ProcessTimes.value>0){  if((Count==document.all.ProcessName.length) || (OldKey!=String.fromCharCode(event.keyCode))){     Count=0;  }          NewKey=String.fromCharCode(event.keyCode);    OldKey=String.fromCharCode(event.keyCode);        Search=false;      for(j=Count;j<document.all.ProcessName.length;j++){         Str=document.all.ProcessName[j].value;              Tmp=Str.substr(0,1);                  if(Tmp==NewKey ){        document.all.ProcessName[j].focus();        document.all.ProcessName[j].select();        Count=j+1;            Search=true;        IfExists=true;        break;        }                Count++;                }                if( Search==false && IfExists==true){      IfExists=false;      Count=0;      document.onkeypress();      }  } } </SCRIPT>

  <table class=txt105 style="BORDER-COLLAPSE: collapse" borderColor=#000000 cellSpacing=0 cellPadding=2 width="100%" bgColor=#ffffff border=1>     <tr>       <td noWrap align=right width="11%">         <Input class=input4 id=ProcessName readOnly size=19 value=ssdfk;d name=textfield416> </td>       <td noWrap align=right width="5%">         <Input class=input4 id=ProcessName readOnly size=8 value=k;lk;kl; name=textfield42> </td>       <td noWrap align=right width="5%">         <Input class=input4left id=ProcessName readOnly size=8 value=kkkk name=textfield43> </td>       <td noWrap align=right width="5%">         <Input class=input4left id=ProcessName readOnly size=8 value=sd name=textfield44> </td>       <td noWrap align=right width="6%">         <Input class=input4 id=ProcessName readOnly size=10 value=jkl; name=textfield45> </td>       <td noWrap align=right width="6%">         <Input class=input4 id=ProcessName readOnly size=10 value=poiuyy name=textfield46> </td>       <td noWrap align=right width="5%">         <Input class=input4 id=ProcessName readOnly size=8 value=kuoiuouhgkh name=textfield47> </td>       <td noWrap align=right width="7%">         <Input class=input4 id=ProcessName readOnly size=12 value=qwetyuyi name=textfield48> </td>       <td noWrap align=right width="5%">         <Input class=input4left id=ProcessName readOnly size=8 value=iuytre name=textfield49> </td>     </tr>     <tr>       <td noWrap align=right width="11%">         <Input class=input4 id=ProcessName readOnly size=19 value=serty name=textfield4> </td>       <td noWrap align=right width="5%">         <Input class=input4 id=ProcessName readOnly size=8 value=mnhgbv name=textfield42> </td>       <td noWrap align=right width="5%">         <Input class=input4left id=ProcessName readOnly size=8 value=sdfghk name=textfield43> </td>       <td noWrap align=right width="5%">         <Input class=input4left id=ProcessName readOnly size=8 value=pmbnvfj name=textfield44> </td>       <td noWrap align=right width="6%">         <Input class=input4 id=ProcessName readOnly size=10 value=yutree name=textfield45> </td>       <td noWrap align=right width="6%">         <Input class=input4 id=ProcessName readOnly size=10 value=mjkl;h name=textfield46> </td>       <td noWrap align=right width="5%">         <Input class=input4 id=ProcessName readOnly size=8 value=fdsa name=textfield47> </td>       <td noWrap align=right width="7%">         <Input class=input4 id=ProcessName readOnly size=12 value=lkjhgf name=textfield48> </td>       <td noWrap align=right width="5%">         <Input class=input4left id=ProcessName readOnly size=8 value=fdsa name=textfield49> </td>     </tr>   <Input type=hidden value=2 name=ProcessTimes>   </table>

  </body>

</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值