[原创]用JS做的一个打字程序(为网友qixiao)

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="JSTestSpeed.aspx.vb" Inherits="zero.JSTestSpeed"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <title>JSTestSpeed</title>
  <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  <Script language="javaScript">
  var str="dsafadsadsf wagfansgasdfaf; asdf;asf sadfasdfsdfsafasdfasfdasfdsafsfsasdfasff";
  var textLength = 60;
  var subStr = "";
  var j=1;
        var tRow=Math.round(str.length/textLength)+1;
       
        var RowMax=0;
  for(i=0;i<str.length;i++){
   subStr = str.substring(i,i+textLength);
   document.write("<input type='text' name='res"+j+"' readonly maxlength="+textLength+" class='res' value='"+subStr+"'>");
   if (subStr.length<textLength)
   RowMax=subStr.length;
   else
   RowMax=textLength;
   document.write("<input type='text' name='des"+j+"'  maxlength="+RowMax+" class='des' onkeyup=checkThis(res" +j+",des" +j+ ","+j+")>");
   document.write(" 本行错误数:<input type='text' name='erow"+j+"' style='width:30px' value=0 >");
      document.write("<p>");
   i=i+textLength-1;
   j=j+1;
   
  }
  
  function checkThis(obj1,obj2,j){
  
   var str1 = obj1.value;
   var str2 = obj2.value;
   
   var t=0;
   var rN=0;
            var theNumber = 0;
   for(i=0;i<str1.length;i++){
    if(str1.substring(i,i+1)!=str2.substring(i,i+1) && str2.substring(i,i+1)!="")
     theNumber=theNumber+1;
    else if (str2.substring(i,i+1)!="")
        rN=rN+1;
    
   }
      document.getElementsByName("erow"+j).item(0).value=theNumber;
      for (var s=1;s<=tRow;s++)
       t=t+parseInt(document.getElementsByName("erow"+s).item(0).value);
  
   document.all("theNumber").value=t;
   document.all("rN").value=rN;
  
  }
  
   
  
  </Script>
  <style>
   body,input{font-size:12px;font-family:verdana;}
  .res{ color:white;width:80%; background-color:royalblue;border:1px solid gray;}
  .des{ color:green;width:80%;border:1px solid gray;}
  input{border:1px solid gray;}
  </style>
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   总错误数目:<input type="text" name="theNumber" readonly value="0" style="width:30px"> &nbsp;正确数目:<input type="text" readonly name="rN" value="0" style="width:30px">
  </form>
 </body>
</HTML>
posted @ 2005-07-08 13:44  PointNet  阅读(542)  评论(0编辑  收藏  举报