私は四角いテーブルを作成する小さなゲームを作成しています。最初のものは左下の部分をクリックすると失われます。テーブルの最後の要素を選択する
私のプログラムで左下の[point:(1,1)]四角形の編集に関する問題があります。私の目標は、
#poison {
width: 5em;
height: 5em;
padding: 0;
background-size: 5em 5em;
background-image: url("http://imgur.com/6Apk8Rk");
}
私.CSSで#poisonをラベルされた、緑色の四角形を持つことである代わりに、私は、現在出力しています定期的な茶色の色の正方形で表示されます。
左下の四角形を#poisonの四角形に置き換える方法がわかりません。
ここでは、テーブルを作成するために使用するJS関数を示します。ここで
function makeTable(x, y) {
var gameTable = document.getElementById('gameTable'),
poison = document.getElementById('poison');
gameTable.innerHTML = null;
var table = [];
//creates rows
for (let i = 0; i < x; i += 1) {
var row = document.createElement('tr');
//appends each row to the table
gameTable.appendChild(row);
//store the amount of iterations in array trow
var tRow = [];
table[i] = tRow;
//create columns (cells)
for (let j = 0; j < y; j += 1) {
let cell = document.createElement('td'); //td defines a cell
//set x,y coordinates
cell.pos = { x: i, y: j };
//stores table values into cell
table[i][j] = cell;
//if you click the bottom left piece of chocolate..
if (i === x - 1 && j === 0) {
cell.onclick = function() {
//..restart the game
restartGame();
}
//else, behave normally
} else {
cell.onclick = function() {
cellClick(cell);
}
}
//append cells to the table
row.appendChild(cell);
}
}
}
は要求によって、関連するHTMLです:
<fieldset id="RowColbox">
<label>
<span>Rows:</span>
<input name="Cols" id="cols" type="number" value="3"/>
</label>
<label>
<span>Columns:</span>
<input name="Rows" id="rows" type="number" value="4"/>
</label>
<button id="addDimensions" type="button">create</button>
</fieldset>
<table id="gameTable">
</table>
Hereはそれの全体が私のコードです。
追加してくださいHTML –
は、関連するHTMLを追加し、全体が – user3335607