对于新的动态创建的元素,单击事件不持久
Click event does not persist for new dynamically created elements
我有一些附加到类的click事件的代码:
$(".filter-link").click(function (e) {
$("#filter").dialog("option", "position",
{ my: "left top", at: "left bottom", of: e });
$("#filter").dialog("open");
});
我所使用的元素通常是动态重新创建的:
function addTopLinks() {
$('#calendar .fc-view thead th.fc-resourceName')
.removeClass('top-calendar-cell');
$('#calendar .fc-view thead th.fc-resourceName')
.addClass('top-calendar-cell');
$('#calendar .fc-view thead th.fc-resourceName')
.html('<a class="filter-link" href="#">Filter Resources</a>');
};
是否有任何方法可以让单击持续存在,或者每次重新创建元素时都会强制重新分配单击?
谢谢
使用.on()
:
$(document).on("click", ".filter-link", function (e) {
$("#filter").dialog("option", "position",
{ my: "left top", at: "left bottom", of: e });
$("#filter").dialog("open");
});
相关文章:
- 将单击事件添加到数据表
- 将单击事件添加到附加的项目中
- 在IE8中不起作用的元素上触发单击事件
- 链接上的IE10 jquery句柄单击事件不起作用
- 如何使用纯 JavaScript 在所有浏览器中区分左/右/中键单击事件
- 如何在master中调用细节网格作为单击事件
- 兰吉 |如何在 span 标签上使用单击事件删除突出显示的文本
- 如何隐藏按钮单击事件上的占位符
- 复选框,然后单击事件处理
- 如何使用for循环添加所有按钮'单击事件
- 手柄'img'单击事件并插入'alt'使用jQuery将属性转换为文本框
- 覆盖单击事件不起作用
- 单击事件打开两个弹出菜单
- 单击事件不起作用
- 从其他元素上的单击事件访问image src属性
- 单击事件中的ajax请求后重定向
- 如何缩放地图框传单中的标记单击事件
- 在没有焦点的情况下捕获画布上的第一次单击事件
- 通过单击事件识别画布上的对象
- 如何将单击事件添加到JQuery中动态添加的元素中