javascript - onclick 事件未在 firefox 4.1 中的 anchor 标记中触发

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

最佳答案

您忘记了 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/

相关文章:

c# - 计划的 .NET WebJob V3 示例

asp.net - 在 MVC 4 中使用 ASP.Net 身份

asp.net - 如何让一个div固定大小,让其他div占据所有剩余空间?

javascript - 从 AQL 获取对象数组

javascript - Mongoose 不保存嵌套对象

javascript - 单击时如何突出显示一个句子?

javascript - 如何使用 grunt 和 browserify 打包我的 Angular 模板

asp.net - Repeater:即使数据源为空也显示页脚

c# - Web Api 中简单 GET 查询的长 TTFB

javascript - 用 mustache 做一个 for-each?