如何为将来的元素应用jquery单击?请参阅下面的代码
$(document.body).on('click', '.testClass', testfunction);
我想只允许单击此代码。我该怎么办?
提前致谢....
答案 0 :(得分:3)
使用one()
$(document.body).one('click', '.testClass', testfunction);
这将为所有 .testClass
元素触发一个点击事件。
如果您要点击一个点击事件按 .testClass
,请手动跟踪是否点击了data-*
个属性
$(document.body).on('click', '.testClass', testfunction);
function testfunction(){
if($(this).data('clicked')) return;
$(this).data('clicked', 1);
/* rest of logic there*/
}