Adding images to an HTML document with javascript

后端 未结 6 1970
故里飘歌
故里飘歌 2020-11-30 04:22

I\'ve tried some HTML DOM code from several sites, but it isn\'t working. It isn\'t adding anything. Does anyone have a working example on this?

this.img =          


        
6条回答
  •  余生分开走
    2020-11-30 04:32

    This works:

    var img = document.createElement('img');
    img.src = 'img/eqp/' + this.apparel + '/' + this.facing + '_idle.png';
    document.getElementById('gamediv').appendChild(img)
    

    Or using jQuery:

    $('')
    .attr('src','img/eqp/' + this.apparel + '/' + this.facing + '_idle.png')
    .appendTo('#gamediv');
    

提交回复
热议问题