使用按钮值编辑文本,然后存储在数组中以比较答案 [英] editing text with button value then storing in array to compare answers

查看:97
本文介绍了使用按钮值编辑文本,然后存储在数组中以比较答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://jsfiddle.net/Victoriamisu/jKvvU/

用户将看到给定的n个字母,例如两个,然后在小提琴中显示屏幕并单击他们看到的两个字母.

The user will see a given n number of letters, let's say two, then will be shown the screen in the fiddle and click on the two letters they saw.

假设首先显示的字母数组是

let's say the array of letters shown first is

var letters = new Array();
            letters = [
                { seq:  1, correct: 'C', display:"C", response:" "},
                { seq:  2, correct: 'X',  display:"X", response:" "}

            ];

我想要它,以便当用户单击其中一个按钮时,比如说她单击了C,它将在第一个方框中打印C,然后将他/她接下来选择的内容打印到小提琴右侧的下一个方框中

I want it so that when the user clicks on one of the buttons, say she clicks on C, it will print C into the first box and then whatever he/she chooses next into the next box on the right in the fiddle.

然后,单击输入按钮将显示一个新屏幕,将答案与正确答案进行比较.因此,.response将更新并与.correct进行比较.

After that, clicking the enter button will show a new screen comparing the answer against the correct ones. So .response will update and be compared to .correct.

我可以在屏幕阵列中加载一个新屏幕,但是如何做到这一点,以便每个按钮的值都作为响应存储?

I can load a new screen in my screen array, but how do I do it so that the value of each button is stored in response?

我在想类似的东西

if( screens[curScreen].lettershow )   // I have the screen set so that it's lettershow:true
                {

            var responseRaw = new String;

            letters[curTrial].response = responseRaw;

并以某种方式使其表明responseRaw = $(#C").val(); (不确定val是否正确,并且C只是这些按钮中任何一个的按钮ID)

and somehow make it show that responseRaw = $("#C").val(); (not sure if val is correct, and C is just the button id for any of those buttons)

此屏幕上的文字将显示 任何一个 正确:您回答_ _(无论用户单击了什么)或不正确,都是一样

The text on this screen will say either correct: you answered _ _ (whatever the user clicked) or incorrect, with the same thing

推荐答案

我更新了jsfiddle,以便用户单击的字母添加到右侧面板. http://jsfiddle.net/jKvvU/5/

I updated your jsfiddle so that the letters that the user clicks are added to the right hand panel. http://jsfiddle.net/jKvvU/5/

我使用了以下jquery:

I used the following jquery:

$(document).ready(function() {
    $(".btnControlLeft").on("click", function() {
        var letterbox = 1;
        while (letterbox < 7 && $("#" + letterbox).html() != "&nbsp;") {
            letterbox++;
        }

        if (letterbox < 7) {
            $("#" + letterbox).html($(this).attr("id"));
        }
    });
})

这篇关于使用按钮值编辑文本,然后存储在数组中以比较答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆