inputテキストフィールド入力しているときに、ある文字を入力すると今までの入力がすべて消されて、text入力欄がまっさらになるようにするにはどうしたらいいのでしょうか?
テキストフィールドを消すために打ったある文字がtext欄に残ってしまいどうしたものかと...。
★印のところの処理を困っております。
よろしければ、ご回答お待ちしております。よろしくお願いします。
lang
1<html> 2<head> 3<link rel="stylesheet" type="text/css" href="style.css"> 4<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5<title></title> 6<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script> 7<script type="text/javascript"> 8 9i=0; 10ichi=0; 11input=""; 12//読み込まれたときに実行される関数 13window.onload= function() { 14 15 //テキスト欄に入力された配列 16 ro_maword="but that was only true for the people who"; //文章 17 ro_malist=new Array(); //文章をsplitで区切ったやつを入れる配列 18 ro_malist=ro_maword.split(" "); //文章をスペースで区切って、配列ro_malisitに入れる 19 ro_ma=""; 20 21 //inputフィールドで入力されたら始まるcheckword()関数を定義 22 $("#inputcontent").keypress(function(event){ 23 ro_ma=ro_malist[i]; 24 checkword(); 25 }); 26 27 28 //ぶつ切りした単語の一文字が入力された文字とあっているかどうか判断する関数 29 function checkword(){ 30 if(ro_ma.charAt(ichi)==String.fromCharCode(event.keyCode)){ 31 seikai(); 32 }else{ 33 machigai(); 34 } 35 } 36 //正解したら 37 function seikai(){ 38 input+=String.fromCharCode(event.keyCode); //input=["b"] 39 $("#inputcontent").val(input.substr(0, input.length - 1)); 40 ichi++; 41 if(ichi==ro_malist[i].length){ 42 document.getElementById("scriptcontent").innerHTML+=ro_ma+" "; 43 empty(); 44 i++; 45 if(i==ro_malist.length){ 46 alert("成功!"); 47 } 48 49 } 50 } 51 //間違ったら 52 function machigai(){ 53 $("#inputcontent").val(input); 54 55 } 56 57 58 function empty(){ 59 input=""; 60 ichi=0; 61 $("#inputcontent").val(""); //★ここでinput text欄を空にしたいと思っているが直前の入力が残ってしまう 62 63 } 64 65} 66 67 68</script> 69</head> 70 71 72<body> 73<div id="main"> 74 <header> 75 <font size="5">出た文字列をタイピングする</font> 76 </header> 77 78 <iframe frameborder="0" height="800" scrolling="no" src="http://ttfaloopandrepeat.appspot.com/showVideo.html?st=120&et=125&vId=RcGyVTAoXEU&l=yes&lnf=10&ap=no" width="100%">your browser does not support IFRAMEs</iframe> 79 80 <div id="scriptcontent"></div> 81 82 <div class="inputfield"> 83 <input type="text" name="inputcontent" id="inputcontent" style="font-size:2em;" /> 84 </div> 85 86 87</div> 88 89</body> 90</html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/03/14 11:15