小编Jos*_*shK的帖子

Javascript:检查周围的表格单元格

我正在制作名为Dots and Boxes的游戏.

网格上有一堆点:

在此输入图像描述

<table>
    <tr>
        <td class="vLine" onclick="addLine(this)"></td>
        <td class="box" onclick="fillBox(this)"></td>
        <td class="vLine" onclick="addLine(this)"></td>
        <td class="box" onclick="fillBox(this)"></td>
        <td class="vLine" onclick="addLine(this)"></td>
        <td class="box" onclick="fillBox(this)"></td>
        <td class="vLine" onclick="addLine(this)"></td>
        <td class="box" onclick="fillBox(this)"></td>
        <td class="vLine" onclick="addLine(this)"></td>
        <td class="box" onclick="fillBox(this)"></td>
        <td class="vLine" onclick="addLine(this)"></td>
        <td class="box" onclick="fillBox(this)"></td>
        <td class="vLine" onclick="addLine(this)"></td>
    </tr>
    <tr>
        <td class="gap"></td>
        <td class="hLine" onclick="addLine(this)"></td>
        <td class="gap"></td>
        <td class="hLine" onclick="addLine(this)"></td>
        <td class="gap"></td>
        <td class="hLine" onclick="addLine(this)"></td>
        <td class="gap"></td>
        <td class="hLine" onclick="addLine(this)"></td>
        <td class="gap"></td>
        <td class="hLine" onclick="addLine(this)"></td>
        <td class="gap"></td>
        <td class="hLine" onclick="addLine(this)"></td>
        <td class="gap"></td>
    </tr> …
Run Code Online (Sandbox Code Playgroud)

html javascript css

9
推荐指数
1
解决办法
758
查看次数

连接四:帮助在函数中使用JQuery

我是编程的新手,我正在尝试制作一个简单的Html/CSS/Javascript/JQuery Connect Four游戏.这是 我到目前为止所拥有的.

唯一的问题是你不能将标记堆叠在一起!这连接四个游戏很糟糕; )!

dropToken()函数内部,我试图创建一个带有if语句的for循环,以查找我尝试将令牌放入的空格是否为白色,否则,tr通过使用var ifor循环中的计数器来升级.

function dropToken(obj, column)
{            
    for (var i == 6; i > 0; i--)
    {
        if ($('table tr:last-child td:nth-child(' + column + ')').css("background-color") == "white")
        {
            $('table tr:last-child td:nth-child(' + column + ')').css("background-color", playerTurn);
        }
    }
    if (playerTurn == "Red")
    {
        playerTurn = "Blue"
        obj.style.backgroundColor = "Blue";   
    }
    else
    {
        playerTurn = "Red"
        obj.style.backgroundColor = "Red"; 
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,此代码使程序无法正常工作.

html javascript css jquery

5
推荐指数
1
解决办法
643
查看次数

删除所有类元素

我已经在课堂上创建了8个div div.

<div class="div"></div>
Run Code Online (Sandbox Code Playgroud)

然后我创建了一个函数,removeDivs()删除每个div.

function removeDivs() {
    divs = document.getElementsByClassName('div')
    for (i = 0; i <= 8; i++) {
        divs.removeChild(divs.childNodes[i])
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?

JSFIDDLE:https://jsfiddle.net/nu8jt766/

html javascript

1
推荐指数
1
解决办法
37
查看次数

消除基于字母的单词

我有一本字典和一个字母表:

import string
alphabet = list(string.ascii_lowercase)
dictionary = [line.rstrip('\n') for line in open("dictionary.txt")]
Run Code Online (Sandbox Code Playgroud)

在函数中,我从字母表中删除一个字母

alphabet.remove(letter)
Run Code Online (Sandbox Code Playgroud)

现在,我想过滤字典以消除包含不在字母表中的字母的单词。

我试过循环:

for term in dictionary:
        for char in term:
            print term, char
            if char not in alphabet:
                dictionary.remove(term)
                break
Run Code Online (Sandbox Code Playgroud)

但是,这会跳过某些单词。我试过过滤器:

dictionary = filter(term for term in dictionary for char in term if char not in alphabet)
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

SyntaxError: Generator expression must be parenthesized if not sole argument
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
29
查看次数

标签 统计

html ×3

javascript ×3

css ×2

jquery ×1

python ×1