当前位置: 代码迷 >> JavaScript >> 为什么以上代码不能动态插入图片
  详细解决方案

为什么以上代码不能动态插入图片

热度:511   发布时间:2012-10-18 13:46:55.0
为什么以下代码不能动态插入图片?
HTML code
 <div class="dashboard-sign"></div>


JScript code
var rootDom=$(".dashboard-sign");
    for(var i=0; i<$(dashboard_statusitems).length;i++) {
        var dashboard_statusitem = dashboard_statusitems[i];
        var status = $(dashboard_statusitem).html();

        var img01 = document.createElement("img");

        if(status=="ok"){
            img01.setAttribute("src", "images/circle_ok_16.png");
            rootDom.appendChild(img01);
        }
        else if(status=="SEND WAITING"){
            img01.setAttribute("src", "images/circle_SEND WAITING_16.png");
            rootDom.appendChild(img01);
        }
        else{
          ``````````````````

        }

    }


------解决方案--------------------
试试:
var rootDom=$(".dashboard-sign");
for(var i=0; i<$(dashboard_statusitems).length;i++) {
var dashboard_statusitem = dashboard_statusitems[i];
var status = $(dashboard_statusitem).html();

var img01 = document.createElement("img");
if(status=="ok"){ img01.src="images/circle_ok_16.png"; }
else if(status=="SEND WAITING"){ img01.src="images/circle_SEND WAITING_16.png"; }
else{ }
rootDom.appendChild(img01);
}
  相关解决方案