0

我试图重用变量“startGame”,我通过该变量声明要附加到“table”元素的“a”元素,以便在后面测试它自己的存在。我为此编写的代码如下:

//Helper function to set HTML Tags attributes
function setAttributes(element, attributes)
{ for (var key in attributes) { element.setAttribute(key, attributes[key]); } }

//Opening screen
var startGame = document.createElement("a");
setAttributes(startGame,
{
    "style" : "float:left; width: 100%; text-align: center;",
    "onclick" : "dealHands()"
});
startGame.appendChild(document.createTextNode("Play"));

var table = document.getElementById("table");
table.appendChild(startGame);

function dealHands()
{
    if (table.childNodes[0].nodeValue == startGame)
    { table.removeChild(startGame); }
    ...
}

到目前为止,代码无法感知“startGame”并且没有任何反应。

4

2 回答 2

0

您不能使用以下设置样式属性:

"style" : "float:left; width: 100%; text-align: center;"

它们必须单独设置。但 IE 不支持style以这种方式更改。你需要:

element.style.cssFloat = "left";    // etc.

在这里讨论

另外,我不会table用作ID。

于 2013-07-24T20:04:16.290 回答
0

我只需要从 if 语句中删除“.nodeValue”,以便在两个 HTML 元素之间进行比较,而不是将值与 HTML 元素进行比较。

于 2013-07-25T17:19:08.923 回答