开发者

createElement background image

开发者 https://www.devze.com 2023-03-06 13:10 出处:网络
I am trying to create a table width javascript and createElement(). My problem is that it does not set any background image (just plain white).

I am trying to create a table width javascript and createElement(). My problem is that it does not set any background image (just plain white). However, if I set the innerHTML of the to an image tag with same path, it works!

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);
}

I also have another开发者_C百科 problem that there's space between each ROW in the table. Here's the DOM Element I'm appending to:

<table id="gameField" cellpadding="0" cellspacing="0"></table>

And the CSS

    * {padding: 0; margin: 0;}
    td {
        min-width: 32px;
        min-height: 32px;
        width: 32px;
        height: 32px;
    }

These problems occur both in Chrome and FF @ ubuntu 11.04. No errors shows in javascript console.

  • jack


Try "url('gfx/tile_"+this.backgrounds[cell]+".png')" (with single quotes around the URL).

0

精彩评论

暂无评论...
验证码 换一张
取 消