テーブル幅のjavascriptとcreateElement()を作成しようとしています。私の問題は、背景画像が設定されていないことです(ただの白)。ただし、のinnerHTMLを同じパスのイメージタグに設定すると、機能します!
create : function () {
var tbody = document.createElement('tbody');
for(i in this.map) {
var tr = document.createElement('tr');
for(j in this.map[i]) {
var td = document.createElement('td');
var cell = this.map[i][j];
td.style.color = "red";
console.log("gfx/tile_"+this.backgrounds[cell]+".png");
td.style.backgroundImage = "url(gfx/tile_"+this.backgrounds[cell]+".png);";
td.innerHTML = "j";
tr.appendChild(td);
}
tbody.appendChild(tr);
}
this.gameDOMelm.appendChild(tbody);
}
また、テーブル内の各行の間にスペースがあるという別の問題もあります。追加するDOM要素は次のとおりです。
<table id="gameField" cellpadding="0" cellspacing="0"></table>
そして、CSS
* {padding: 0; margin: 0;}
td {
min-width: 32px;
min-height: 32px;
width: 32px;
height: 32px;
}
これらの問題は、Chrome と FF @ ubuntu 11.04 の両方で発生します。javascript コンソールにエラーは表示されません。
- ジャック