日期:2014-05-16  浏览次数:20408 次

为什么以下代码不能动态插入图片?
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);
}