representing a character at various array in an html table w/JQuery/JavaScript

后端 未结 3 800
青春惊慌失措
青春惊慌失措 2021-01-23 18:27

I\'ve run into some issue graphically representing some of my data via J Query in my Hangman game- right now I\'m working on the last part of my play(space) function to take int

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-23 19:15

    Note that when you make a selection you get the following error in the console:

    Uncaught Error: Syntax error, unrecognized expression: :nth-of-type

    That's because of this line:

    $(".word-spaces tbody tr td:nth-of-type(" + indexes + ")").css('color', 'black');
    

    Since a correct guess can set multiple indexes, you'll need to use a loop for the correct guesses like this:

    $.each(indexes,function(e,i){
        $(".word-spaces tbody tr td:nth-of-type(" + i + ")").css('color', 'black');
    })
    

    Additionally, I think this line is wrong:

     $(".word-spaces > tbody > tr").append('' + word[i] + '')
    

    You probably meant to use the value of i like this:

    $(".word-spaces > tbody > tr").append('' + word[i] + '')
    

    (though you dont really need the data-idx attribute at all since it will always be the same as the child index within the tr tag and you're using that to get the cells anyway)

    Here is a working jsFiddle

提交回复
热议问题