javascript - 向文本序列添加计数器

标签 javascript html css counter

目前我正在开发一款游戏,我正在使用 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);
    },

任何帮助都会很棒

最佳答案

只需更改输出文本的行:

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

更新 fiddle :http://jsfiddle.net/uusL7hch/18/

关于javascript - 向文本序列添加计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26909862/

相关文章:

html - 在 IE 8 及以下版本中标题消失并且列表变得无样式

jquery - 如何仅使用 css 设计像 mashable 中那样的搜索面板

html - 嵌入来自YouTube,Vimeo等的视频

jquery - 无法正确定位 html 菜单元素 (Jquery)

html - 在 HTML 中,为什么要将分段元素放在列表中?

javascript - 在 Ember.js 中加载关联模型

javascript - 当该部分的 id 作为 iink 单击时,如何使页面滚动到该部分的顶部

javascript - AngularJS 输入检查/取消检查有 2 个函数

javascript - Angular js 将 'file' 类型更改为 'text' 类型 [Safari]

javascript - 如何将自定义 Memory 对象传递给 WebAssembly?