onclick事件没有在firefox4.1中的anchor标签中触发


 var ni =  document.getElementById("fileDiv");
 var objFileCount = document.getElementById("fileCount");
 var num = (document.getElementById("fileCount").value - 1) + 2;
 objFileCount.value = num;
 var newdiv = document.createElement("div");
 var divIdName = "file" + num + "Div";
 newdiv.id = divIdName;
 //newdiv.setAttribute("id", divIdName);
 newdiv.innerHTML = '<input type="file" name="attachment" id="attachment"/> <a name="#"  onclick="removeFile(' + divIdName + ');" style="color:blue;cursor:pointer;">Remove</a> ';
 ni.appendChild(newdiv);

 function removeFile(divName) {
           alert(divName);
           var d = document.getElementById("fileDiv");
           d.removeChild(divName);
 }

您忘记了divIdName:的引号

newdiv.innerHTML = '<input type="file" name="attachment" id="attachment"/> <a name="#"  onclick="removeFile('' + divIdName + '');" style="color:blue;cursor:pointer;">Remove</a> ';

此外,在发布问题时,请详细说明您的问题;不要只是发布代码并期望得到答案。

最新更新