如何将以下内容绑定(bind)到将来可能动态添加到我的页面的所有复选框实例。我不确定如何使用 Live() 方法来执行此操作。
$('input:checkbox').imageTickBox({
tickedImage: "/Content/Img/checkbox_tick.png",
unTickedImage: "/Content/Img/checkbox_notick.png",
imageClass: "tickbox"
});
最佳答案
您不能使用 .live()
执行此操作(或.delegate()
)。这些用于绑定(bind)可能尚不存在的事件的事件处理程序。
Description: Attach a handler to the event for all elements which match the current selector, now and in the future.
您正在使用的图像勾选框插件不是任何类型的“事件”。每当添加新复选框时,您都必须显式调用初始化代码(例如 $('selector').imageTickBox(...)
)。
关于javascript - 使用 Live 方法将函数绑定(bind)到动态创建的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5899126/