请问js的Jquery和zepto用fn对一个元素点击绑定了一个功能!怎样解绑?

如下面:页面载入时 点击 div 弹出提示框!但我想点击 stop click 的时候,取消对ABC 的事件绑定。怎样实现??<div class=✀ABC✀ height = ✀50px✀ > click me ! </div><div class=✀CCC✀ > stop click ! </div>---------------------------$(function(){ $(✀.ABC✀).swipeSS();});;(function(win,$){ $.fn.swipeS = function(options){ return this.each(function(){ $(this).on("touchstart", function(event) { alert( $( this ).css(✀height✀) ); } }}swipeSS 按多了一个字符..... 其实 是 swipeS!
2026年09月25日 01:15
有1个网友回答
网友(1):

先看下jquery $.fn $.fx是什么意思

$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效。
如扩展$.fn.abc(),即$.fn.abc()是对jquery扩展了一个abc方法,那么后面你的每一个jquery实例都可以引用这个方法了.
那么你可以这样子:$("#div").abc();


这个您最好做一个全局的变量来判断,这样才好控制其执行与不执行,省去多余的重复的绑定。

另外一种就是实例开始已经对元素绑定了事件,那么只需要unbind其事件即可,前提是fn里的绑定事件也是用bind绑定的。

var isbind=true;
function jiebang(){
isbind=false;
}

$(function(){
    $('.ABC').swipeSS();
});
;(function(win,$){
    $.fn.swipeS = function(options){
    return this.each(function(){

        $(this).on("touchstart", function(event) {
        if(!isbind){return;}//这里判断
             alert( $( this ).css('height') );
        }
    }

}