大佬教程收集整理的这篇文章主要介绍了jquery – 在可能多次调用的事件上只调用一次特定函数?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$('.theImage').live("click",function(){ // The commands within the if statement must only happen on the first click. if (!chkHeightOnceOnly){ var containerHeight = $(this).children(".posTinfo").height(); $(this).children(".posTinfo").height(containerHeight - 2); var chkHeightOnceOnly = true; } // other commands which need to fire on every click go here });
因此,目前每次点击div,它都会减去2px.它只需要第一次减去2px.
编辑 – 这是针对.theImage的许多实例,它们是通过ajax进入的,因此需要.live()
$('.theImage').live("click",function(){ // The commands within the if statement must only happen on the first click. if ($(this).attr('data-once')!='already' ){ var containerHeight = $(this).children(".posTinfo").height(); $(this).children(".posTinfo").height(containerHeight - 2); $(this).attr('data-once','already'); } // other commands which need to fire on every click go here });
以上是大佬教程为你收集整理的jquery – 在可能多次调用的事件上只调用一次特定函数?全部内容,希望文章能够帮你解决jquery – 在可能多次调用的事件上只调用一次特定函数?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。