我用js动态将一些图片绑定到一个div中~
代码如下:
function loadFace()
{
face = document.all("faceContainer"); //div名称
var strTable = "<table border= \"1\" cellpadding=\"0\" cellspacing=\"0\">"; 
var i,j,count;
count = 0;
for(i=0;i<7;i++)
{
strTable += "<tr>";
for(j=0;j<14;j++)
{

if(count <=95)
{
strTable += "<td><img src='Face/" + count + ".gif' onclick=\"insertFace('" + count + "')\"/></td>";
}
else
{
strTable += "<td>&nbsp;</td>";
}
count++;
}
strTable += "</tr>";
}
strTable += "</table>";
face.innerHTML = strTable; //将table添加到div中
}
这个方法可以将图片添加进去~~
但是在方法中我给每张图片添加了onclick事件,将选择的图片添加到一个txtbox中
写了JS如下:function insertFace(index)
{
    alert(index); //测试,是否获得Id
    editor.focus(); //获得txtbox的焦点
    editor.document.execCommand('InsertImage',false,"Face/" + index + ".gif");
}但是这个js执行不了~
忘高手指点~在线等~~~~急~

解决方案 »

  1.   

    editor.document.execCommand('InsertImage',false,"Face/" + index + ".gif");
    to
    editor.document.execCommand('InsertImage',false,"Face//" + index + ".gif");
    试试看
      

  2.   

    现在是这个
    alert(index); //测试,是否获得Id
    都不会弹出来~~
      

  3.   


    试试
    strTable += "<td><img src='Face/" + count + ".gif' onclick='insertFace(" + count + ");'></td>";
      

  4.   

    <img src='Face/" + count + ".gif' onclick=alert('123')>
    看看,img的onclick是否能执行?先别管能否调用其他方法。先看,你点击的时候,img的onclick有没有触发,是不是有别的什么程序阻挡了,或者,你加了什么方法,有js代码,将png的图片,在ie6下也能使其透明,这种代码就会把当前img变成div的。也就是说,存在这类代码的话,页面上实际已无img控件了