0

誰かがそのテキストボックスに何かを入力したときにテキストフィールドにaからzを表示するコードを書きましたが、そのコードでは、ユーザーがスペースバーキーを押したときにaからzを1つずつ表示する必要があり、前の文字も変更しますスペースバーが押されたときの色なので、それを行うのを手伝ってもらえますか、これが私のコードです

<html>
<head>
<script>
    var x=0
    function type()
    {
        var a=newArray("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
       var i=document.getElementById("type").value
       var n=i.substring(0,i.length-1)
       document.getElementById("type").value=n.concat(a[x]);
       if(x>=0)x++
       if(x>=26)x=0 
     }
</script>    
</head>
<body>
<input type="text" name="type" id="type" size="100" onkeyup="type()">
</body>
</html>
4

1 に答える 1

0

どうぞ!

var letter_array = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];

var pointer = 0; // start the pointer at 0 which means that the first letter will show is the a
var shown_letters=''
$('#type').keydown(function (e) {
     if (e.keyCode == 32) { 
         if(pointer+1 == 26){
         pointer = 0;
         }
         shown_letters += letter_array[pointer];
         $('#type').val( shown_letters);
         pointer = pointer+1
       return false; // return false to prevent space from being added
     }
});

また、テキスト入力で最後の文字を他の文字とは異なるスタイルにすることはできません

http://jsfiddle.net/m4eJx/

于 2013-01-28T07:40:48.227 に答える