2014-12-27 31 views
0

注意:此代碼適用於所有瀏覽器BESIDES Firefox,是的, m使用最新版本。Javascript BlackJack腳本沒有在Mozilla Firefox中的按鈕執行/調用「hitMe()」和「stand()」功能

注意:我只包括有問題的代碼,其他一切工作正常。

當我編寫下面的代碼時,Firefox會加載其他一切正常。

瀏覽器會接受第一個按鈕功能(一個按鈕調用的功能),但不接受第二個或第三個按鈕功能。

未提供給我的代碼中包含的「優惠」按鈕正常工作。它打印一個新頁面。

現在當打印新頁面時,出現「點擊」和「站立」按鈕。問題是...

...這些按鈕不會像「Deal」按鈕那樣打印新頁面。

我相信問題是要定義的功能或其內部的內容。

//**** 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

+0

該問題可以通過清除緩存來解決。也許試試看? –

+0

對不起,我已經嘗試過這種解決方案,但迄今爲止沒有任何進展,但感謝您爲幫助我所做的努力。 – CA1K

+0

只是檢查了這一點https://support.mozilla.org/en-US/questions/751899 –

回答

0

hitme擋在Firefox中不會工作,因爲這些功能是不確定的,當你給他們打電話。

  • 轉到您的網頁在Firefox中,右鍵單擊並選擇查看源。查看你所有的代碼?
  • 現在,點擊優惠。當頁面更改時,右鍵單擊並再次選擇查看源。看看你的所有javascript代碼已經消失了嗎?

這是因爲您的printCards()(以及您的所有功能)錯誤地使用了document.write。其他瀏覽器如chrome是寬容的,並且會讓你擺脫這種困境,但是在Firefox中,當你覆蓋之前在頁面上的信息時(包括javascript代碼本身),你可以使用它。

您需要更改所有document.write用法使用DOM功能,而不是像document.getElementById('mydiv').innerHTML += '<td>My New Card</td>'

和你document.cleardocument.getElementById('mydiv').innerHTML ='';

你可能將不得不調整你的造型與這些變化工作也。