我試圖使用JavaScript創建一個遊戲,但前進的道路上,我發現在Firefox中的錯誤。遊戲很簡單。你應該猜測RGB hexacode中的顏色是什麼。有6個框,你應該點擊框,如果它錯誤或正確,它會發出警報。該遊戲在Chrome,IE,Opera中運行良好,但在Mozilla Firefox中不起作用。我做了一個警告來調試它,Firefox用它添加一些內聯樣式。請參閱下面的屏幕截圖和代碼。希望你能幫助我如何解決這個問題在Firefox中。在此先感謝的Mozilla瀏覽器的bug
FIREFOX SCREENSHOT PROBLEM CHROME SCREENSHOT NO PROBLEM
<!DOCTYPE html>
<html>
<head>
<title>Color Game</title>
<style type="text/css">
\t body{
\t \t background-color: #232323;
\t }
\t h1 {
\t \t color:#fff;
\t }
\t .square {
\t \t width: 30%;
\t \t background: purple;
\t \t padding-bottom: 30%;
\t \t float: left;
\t \t margin: 1.66%;
\t }
\t #container {
\t \t max-width: 600px;
\t \t margin: 0px auto;
\t }
</style>
</head>
<body>
<h1>Guess what color is<span id="colorDisplay">RGB</span>
<br/>
Click the box to know what color it is.
</h1>
<div id="container">
\t <div class="square"> </div>
\t <div class="square"> </div>
\t <div class="square"> </div>
\t <div class="square"> </div>
\t <div class="square"> </div>
\t <div class="square"> </div>
</div>
<script type="text/javascript">
\t
\t var colors = [
\t "rgb(255, 0, 0)",
\t "rgb(255, 255, 0)",
\t "rgb(0, 255, 0)",
\t "rgb(0, 255, 255)",
\t "rgb(0, 0, 255)",
\t "rgb(255, 0, 255)"
\t ];
\t var squares = document.querySelectorAll(".square");
\t var pickedColor = colors[1];
\t var colorDisplay = document.querySelector("#colorDisplay");
\t colorDisplay.textContent = pickedColor;
\t for (var i=0; i<squares.length; i++){
\t \t //add initial colors to square
\t \t squares[i].style.background = colors[i];
\t \t //add click listener to square
\t \t squares[i].addEventListener("click",function(){
\t \t \t var clickedColor = this.style.background;
\t \t \t alert(clickedColor);
\t \t \t if (clickedColor === pickedColor){
\t \t \t \t alert("Correct");
\t \t \t } else{
\t \t \t \t alert("Wrong");
\t \t \t }
\t \t });
\t }
</script>
</body>
</html>
謝謝你們所有的幫助! – JackOfAllTrades