2016-10-12 5 views
0

これは、正しい方法でメッセージをインポートするかどうかわかりません。入力する代わりに任意のキーを使用する:任意のキーを使用して、キーを押すと一度に1つずつ表示したい文字列の配列を持っています

use strict"; 
var queue = lyrics; 

$(document).keyup(function){ 
    if (event.keyCode >= 48 && event.keyCode <= 90){ 
     var val= queu.shift(); 
     $(".lyrics").append(val); 
    } 
}) 

var lyrics =[ 
     "I took a vow that from now on Im gonna be my own best friend", 
     "Perfection is the disease of a nation", 
     "I took some time to live my life. But dont think Im just his little wife.", 
     "There's nothing not to love about me. I'm lovely.", 
     "My persuasion can build a nation.", 
     "Some call it arrogant. I call it confident", 
     "Goddammit I'm comfortable in my skin", 
     "Stop making a big deal out of the little things", 
     "I wake up looking this good. And I wouldn't change it if I could", 
     "A little sweat ain't never hurt nobody" 
    ]; 

答えて

0

多分このような何か?

var lyrics =[ 
     "I took a vow that from now on Im gonna be my own best friend", 
     "Perfection is the disease of a nation", 
     "I took some time to live my life. But dont think Im just his little wife.", 
     "There's nothing not to love about me. I'm lovely.", 
     "My persuasion can build a nation.", 
     "Some call it arrogant. I call it confident", 
     "Goddammit I'm comfortable in my skin", 
     "Stop making a big deal out of the little things", 
     "I wake up looking this good. And I wouldn't change it if I could", 
     "A little sweat ain't never hurt nobody" 
    ]; 
    $(document).on('keyup', function(event){ 
     if (lyrics.length) { 
     if (event.which >= 48 && event.which <= 90) { 
      $('.lyrics').append(lyrics.shift()); 
     } 
     } else { 
     console.log('no more lyrics'); 
     } 
    }); 
関連する問題