+ -
当前位置:首页 → 问答吧 → 模拟打字程序(未完成,很烂)

模拟打字程序(未完成,很烂)

时间:2009-03-25

来源:互联网

突然好玩,想到模拟一下打字程序
以前有见过网上的打字程序,别人写的很好很强大
我这里无聊写了几句,也不知道该不该发帖,有点浪费论坛空间。
姑且做个标记吧,大家讨论,或自己以后再改改...

复制代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title>Events</title>
  5.      <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
  6.     <style type="text/css">
  7.         textarea
  8.         {
  9.             height: 118px;
  10.             width: 100%;
  11.         }
  12.     </style>
  13.     <script type="text/javascript">
  14.         $(function(){
  15.             var Texts = "slsieowkdlskdjpaosodkllsldksldlaskdjfja;sdlddThis is where the fun part comes in. Now that we are reading the XML, we need to find the data written within it and do something with it. We start by reading the returned data and using the find method to get all the nodes that match the text we supply (in this case, “site”), and then use the each function to loop through what the find function give to us.".split("");
  16.             var t = "";
  17.             for(var i=0; i<Texts.length; i++){
  18.                 t += "<span id='t"+ i +"' class='ok'>" + Texts[i] + "</span>"
  19.             }
  20.             $('#result').html(t)
  21.             $('textarea').bind('keyup',function(){
  22.                 var inputstr = $('textarea').val();
  23.                 var ouputstr = $('#result>#t' + (inputstr.length-1)).text();
  24.                 if(window.event.keyCode  == 8){
  25.                     $('#result>#t' + (inputstr.length) ).css("background-color", "white")
  26.                 }
  27.                 else{
  28.                     if(inputstr.substr(inputstr.length-1) != ouputstr)
  29.                         $('#result>#t' + (inputstr.length-1) ).css("background-color", "red")
  30.                     else
  31.                         $('#result>#t' + (inputstr.length-1) ).css("background-color", "white")
  32.                 }
  33.             }
  34.             );
  35.         });
  36.     </script>
  37. </head>
  38. <body>
  39.     <div id='result' style="line-height:25px;letter-spacing:2px;"></div>
  40.     <textarea></textarea>
  41. </body>
  42. </html>


还有好多问题没解决,比如一直按下某个键等等.....

作者: net205   发布时间: 2009-03-25

支持分享~

作者: shawphy   发布时间: 2009-03-26