onclick事件未在firefox 4.1中的锚标记中触发

时间:2011-06-20 13:13:15

标签: javascript asp.net

 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);
 }

1 个答案:

答案 0 :(得分:3)

您忘记了divIdName的引号:

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

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

相关问题