Javascript 文本框更新

Javascript 文本框更新,javascript,jquery,Javascript,Jquery,我试图用数组更新userPoints文本框 var points = new Array(); points[0] = [10]; points[1] = [15]; points[2] = [5]; points[3] = [10]; points[4] = [15]; points[5] = [10]; points[6] = [15]; points[7] = [10]; points[8] = [15]; points[9] = [15]; function rightOr

我试图用数组更新userPoints文本框

var points = new Array();    
points[0] = [10];
points[1] = [15];
points[2] = [5];
points[3] = [10];
points[4] = [15];
points[5] = [10];
points[6] = [15];
points[7] = [10];
points[8] = [15];
points[9] = [15];  

function rightOrWrongAnswer(){
    $("#choiceSelector > ol > li").click(function() {
        // for userChoice when they click, turn it into text
        var userChoice = $(this).text();

        // userChoice equals answers    
        if(userChoice == answers[count]){

            // change that answer to green
            $(this).css("color", "green");
我认为这就是下面这条线的问题所在

// update the points box
userPoints += points[0];
或者可能是在我更新文本框时

        $("#userPoints").val(points[count]);
    }
});

从RightorErrorAnswer()移动以下块

displayNextQuestion(){


计算点不在正确的位置。再次检查它们。这是一个示例,您的答案移动到下一个问题答案。使用alert检查发生了什么。

从RightorErrorAnswer()移动以下方框

displayNextQuestion(){


计算点不在正确的位置。请再次检查它们。这是一个示例,您的答案将移动到下一个问题答案。使用alert检查发生了什么。

因为您的
点是一个数组,您需要按索引访问它

// update the points box
userPoints += points[count][0];
$("#userPoints").val(points[count][0]);
$("#totalScore").val(userPoints);
相反,如果您按如下所示定义了
,那么您的代码就可以工作了

var points = [ 10, 15, 5, 10, 15, 10, 15, 10, 15, 15 ];
userPoints += points[count];
$("#userPoints").val(points[count]);
$("#totalScore").val(userPoints);
经过一些边界检查,这里有一把工作小提琴


由于您的
点是一个数组,您需要通过索引访问它

// update the points box
userPoints += points[count][0];
$("#userPoints").val(points[count][0]);
$("#totalScore").val(userPoints);
相反,如果您按如下所示定义了
,那么您的代码就可以工作了

var points = [ 10, 15, 5, 10, 15, 10, 15, 10, 15, 15 ];
userPoints += points[count];
$("#userPoints").val(points[count]);
$("#totalScore").val(userPoints);
经过一些边界检查,这里有一把工作小提琴


你能给一个JSFIDLE PLEALERIGHT稍等片刻吗?你能给一个jsfiddle稍等片刻吗?你能给一个jsfiddle PLEALERIGHT稍等片刻吗?你能给一个jsfiddle稍等片刻吗e问题变得混乱,文本框值仍然没有更新。