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);
}
答案 0 :(得分:3)
您忘记了divIdName的引号:
newdiv.innerHTML = '<input type="file" name="attachment" id="attachment"/> <a name="#" onclick="removeFile(\'' + divIdName + '\');" style="color:blue;cursor:pointer;">Remove</a> ';
此外,请在发布问题时详细说明您的问题;不要只发布代码并期待答案。