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> ';
另外,请在发帖时详细说明您的问题;不要只是发布代码并期待答案。
关于javascript - onclick 事件未在 firefox 4.1 中的 anchor 标记中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6411684/