我以这种方式附加了一个跨度的点击事件。跨度在表内。
$("#tblImport").find("span").each(function () {
$(this).click(function () {
appendData(this);
});
});
此事件处理程序“appendData”发出 ajax 请求并获取数据。
function appendData(prntSpan) {
$(prntSpan).append(createElements());//ajax call.
updateEvents(prntSpan);
}
我想要的是分离这个点击事件处理程序并附加一个新的。所以我尝试了这个。
function updateEvents(curntSpan) {
$(curntSpan).off('click');//this works
$(curntSpan).off('click', appendData);// but this does not work strange
$(curntSpan).on('click', toggleData(curntSpan));//nor a new click handler is attached
}
执行上面使用 .on 的行时调用该函数,但之后单击 span 时不会触发任何事件。