jquery - Chrome 中的表格行为

标签 jquery css class google-chrome css-tables

我正在创建一个简单的内存游戏,出于某种原因,当我在 chrome 中添加和删除类时,表格单元格会展开。谁能告诉我为什么会这样? 这是我用来在单击时添加和删除类的脚本。这就是整个 fiddle 。 http://jsfiddle.net/stoney265/4XznK/

$('td').click(function () {
    if ($(this).hasClass('clicked') || $(this).hasClass('completed')) {
        $(this).stopPropagation();
        $(this).preventDefault();
        return;
    }
    $(this).addClass('clicked');
    tempArr.push($(this).text());
    var len = tempArr.length;
    if (len > 1) {
        if (tempArr[0] === tempArr[1]) {
            alert("Good job!");
            $('.clicked').addClass('completed');
            $('.completed').removeClass('clicked');
            winCounter = winCounter + 1;
        } else {
            alert("Try again!");
            $('.clicked').removeClass('clicked');
        }
        tempArr.splice(0, 2);
    }
    if (winCounter === countCells / 2) {
        alert('You won!');
    }
    console.log(countCells, winCounter);
});

最佳答案

text-indent 属性导致了这个问题。

您可以通过将背景更改为黑色或将文本颜色更改为白色来达到所需的效果

http://jsfiddle.net/4XznK/13/

table td {
    border: 1px solid black;
    height: 40px;
    width: 30px;
    text-align: center;
    overflow: hidden;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: default;
    /* background black */
    background-color: #000;
}
.clicked {
    text-indent: 0;
    text-align: center;
    height: 40px;
    width: 30px;
    table-layout: fixed;
    white-space: nowrap;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: default;
    /* background white */
    background-color: #fff;
}
.completed {
    background-color: white;
    overflow: hidden;
    height: 40px;
    width: 30px;
    table-layout: fixed;
    white-space: nowrap;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: default;
}

关于jquery - Chrome 中的表格行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17329638/

相关文章:

c++ - 将内联方法从头文件移动到 .cpp 文件

jquery - 在发送下一个请求之前中止 ajax 请求? (jQuery)

jquery - jquery脚本文件如何获取Asp.Net MVC 3的路由数据的ID值?

jquery - 如何在物化CSS中获取下拉列表的数据值?

javascript - 在html页面中动态添加form元素和table元素

php - 如何为对象创建默认值? PHP

javascript - HTML5 checkValidity 和不可见字段

javascript - 如何从父元素中删除事件并仅为其特定子元素启用该事件?

javascript - 在空间和位置方面添加特定类

java - 从 MATLAB 调用 Java