0

注意:此代码适用于除 Firefox 之外的所有浏览器,是的,我使用的是最新版本。

注意:我只包括有问题的代码,其他一切正常。

当我编写下面的代码时,Firefox 会很好地加载其他所有内容。

浏览器将接受第一个按钮功能(由按钮调用的功能),但不接受第二个或第三个按钮功能。

我提供给您的代码中未包含的“交易”按钮可以正常工作。它打印一个新页面。

现在,当打印新页面时,会出现“Hit”和“Stand”按钮。问题是...

...按钮不会像“交易”按钮那样打印新页面。

我相信问题要么是函数的定义,要么是函数内部的内容。

//**** STAND FUNCTION START DEALS DEALER CARDS ****
function stand()
/*Altough we have a "printCards" function, we will print the cards
differently in the stand function. Why? When the first cards are printed,
we have a hidden one, thus showing the hidden card in this function*/
{
dealerAcesTotal = dealerTotal;
if (dealerAcesTotal == 22){(dealerAcesTotal = 12);}

//KEEP DEALING CARDS TO THE DEALER WHILE THE HAND IS UNDER 17
while (dealerAcesTotal < 17)
{
randA = Math.floor((Math.random()*52)+1);//for the dealer
dealerCards[dealerHits] = card[randA];
dealerTotal = (dealerTotal + dealerCards[dealerHits][3]);
if (dealerCards[dealerHits][3] == 11){dealerAces = (dealerAces + 1);}
dealerHits = (dealerHits + 1);
dealerAcesTotal = dealerTotal;
}
//end of KEEP DEALING CARDS TO THE DEALER



//add a new row for totals and DEAL button
document.write("</TR><TR><TD align=center><FONT color=white><kbd>Dealer = " +     dealerAcesTotal + "</TD>");
document.write("<TD align=center><FONT color=white><kbd>Player = " + playerAcesTotal +     "</TD>");
document.write("<TD align=center><FONT color=white><kbd>BET = $" + bet + "</TD>");
document.write("<TD align=center><FONT color=white><kbd>" + handText + "<BR>"+ name    +"'s&nbsp;Bank: $" + currentBank + "</TD>");
document.write("<TD align=center><FONT color=white><kbd><button onclick=\"\dealCards    \(\)\">Deal</button></TD>");
document.write("</TR><TR>");
//****END OF PRINT CARDS TO FINISH HAND SCREEN
document.close();
return;
}
//**END OF STAND FUNCTION**

function hitMe(){playerHit();} //a sort of test for the browser...
//****PLAYER HITS FOR A NEW CARD****
function playerHit()
{
randA = Math.floor((Math.random()*52)+1);//for the player
playerCards[playerHits] = card[randA];
playerTotal = (playerTotal + playerCards[playerHits][3]);
if (playerCards[playerHits][3] == 11){playerAces = (playerAces + 1);}
playerHits = (playerHits + 1);
playerAcesTotal = playerTotal;
// run a loop for as many aces in the hand
//if the playerTotal is over 21 deduc
for (i = 0; i< playerAces; i++)
{
if ( playerAcesTotal > 21){playerAcesTotal = (playerAcesTotal - 10);}
}
printCards();
//document.close();
//return;
}

非常感谢您的反馈。:)

PS:我的脚本在当前页面:http ://ca1k.xkotto.com/portfolio/BLACKJACKV10.html

4

1 回答 1

0

hitme 和 stand 在 firefox 中不起作用,因为调用它们时这些函数是未定义的。

  • 在 Firefox 中转到您的页面,右键单击并选择查看源代码。查看所有代码?
  • 现在,点击交易。当页面发生变化时,右键单击并再次选择查看源。看看你所有的 javascript 代码是如何消失的?

这是因为您printCards()(实际上是您的所有功能)错误地使用了document.write. 其他浏览器(如 chrome)是宽容的,可以让您摆脱这种情况,但在 Firefox 中,当您这样做时,您会覆盖页面上先前的信息(包括 javascript 代码本身)。

您需要更改所有document.write用法以使用 DOM 函数,例如document.getElementById('mydiv').innerHTML += '<td>My New Card</td>'

document.clear会是document.getElementById('mydiv').innerHTML ='';

您可能还必须调整样式以适应这些更改。

于 2014-12-27T10:13:13.943 回答