【问题标题】:Adding a Counter to a Text Sequence向文本序列添加计数器
【发布时间】:2014-11-13 13:20:08
【问题描述】:

目前我正在开发一个游戏,我正在使用 JavaScript 进行游戏

其中一个功能允许用户查看他们必须输入的序列(它会打印出他们必须点击的颜色)

但问题是有时他们必须打同一个圆圈两次等,这对用户来说不是很清楚。

所以我想知道是否可以在序列中添加一个计数器来显示像

这样简单的东西

1.红色

2.红色

3.蓝色

所以他们可以看到它想要第二个红色等

这是一个 jsfiddle,所以你可以明白我的意思 http://jsfiddle.net/uusL7hch/17/

JavaScript 文件只缩减到显示颜色名称的代码所在的部分

        $.each(this.genSequence, function (index, val) { //iterate over each value in the generated array
            timerCount = index;
            setTimeout(function () {

                that.flash($(that.shape + val), 1, 300, val);
                if ($("#text").is(":checked")) {//Check Box Function

                $(".TextBox").children(":first").html('<b>' + that.colors[val - 1] + '</b>');
                }
            }, 500 * index * that.difficulty); // multiply timeout by how many items in the array so that they play sequentially and multiply by the difficulty modifier

        });

        // Wait to start timer until full sequence is displayed
        setTimeout(function () {
            that.timerInterval = setInterval(function () {
                that.countDown()
            }, 100)

            setTimeout(function () {
                $(".TextBox").children(":first").html('');
            }, 500);
        }, 500 * timerCount * that.difficulty);
    },

任何帮助都会很棒

【问题讨论】:

  • 能否将您的代码缩短为相关的代码行?
  • @GottliebNotschnabel 代码减少让你明白这一点

标签: javascript html css counter


【解决方案1】:

只需更改输出文本的行:

$(".TextBox").children(":first").html('<b>' + (index + 1) + ":" +that.colors[val-1]+'</b>');

更新小提琴:http://jsfiddle.net/uusL7hch/18/

【讨论】:

  • 完美 这么简单的事情让我卡了大约一个小时,感谢您的帮助
【解决方案2】:

你需要为你的数据列表定义css个人标签:

ol#your_list_name {
    list-style-type:decimal;
}

【讨论】:

  • 那是行不通的,因为它正在打印 javascript 文件,我需要为每个序列设置一个计数器
猜你喜欢
  • 2021-12-15
  • 2012-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多