2011-08-31 7 views
0

jsfiddle、.bindを使用していましたが、現在.delegateを使用しています... .undelegateを試しましたか?相続人

jsfiddle.net/kqreJは、だから私は、この関数には、問題を.bind使用していなかったが、その後、私は、ページに複数の更新プログラムをロードし、ページにインポートされたコンテンツのため.bind動作しないことが分かったが、既にページ上にあるコンテンツ用です!すばらしいです!

だから私はそれを非常にクールですが、今私はどのように.bind .bind私の機能をバインドする方法を理解することができません.delegate ???

AJAXコンテンツでは動作しませんでしたを除いて...完璧な仕事を.bindを使用して機能.. :(

$('.open').bind("mouseup",function(event) { 
var $this = $(this), handler = arguments.callee; 
$this.unbind('mouseup', handler); 
var id = $(this).attr("id"); 
var create = 'nope'; 

    var regex = /\d+$/, 
    statusId = $('#maindiv .open').toArray().map(function(e){ 
     return parseInt(e.id.match(regex)); 
    }); 

var divsToCreate = [ parseInt(id) ]; 

$.each(divsToCreate, function(i,e) 
{ 
    if ($.inArray(e, statusId) == -1) { 
     create = 'yup'; 
    } 
}); 

     if(create == 'yup') { 
      if(id) { 
        $.ajax({ 
        type: "POST", 
        url: "../includes/open.php", 
        data: "post="+ id, 
        cache: false, 
        success: function(html) { 
        $('.open').html(html); 
        $this.click(handler); 
        } 
        }); 
      } 
     } 

}); 

バインドさや複数のインスタンスを作成していない.delegateを使用して新機能?

$('#maindiv').delegate("span.open", "mouseup",function(event) { 
var $this = $(this), handler = arguments.callee; 
$this.unbind('mouseup', handler); 
var id = $(this).attr("id"); 
var create = 'nope'; 

    var regex = /\d+$/, 
    statusId = $('#maindiv .open').toArray().map(function(e){ 
     return parseInt(e.id.match(regex)); 
    }); 

var divsToCreate = [ parseInt(id) ]; 

$.each(divsToCreate, function(i,e) 
{ 
    if ($.inArray(e, statusId) == -1) { 
     create = 'yup'; 
    } 
}); 

     if(create == 'yup') { 
      if(id) { 
        $.ajax({ 
        type: "POST", 
        url: "../includes/open.php", 
        data: "post="+ id, 
        cache: false, 
        success: function(html) { 
        $('.open').html(html); 
        $this.click(handler); 
        } 
        }); 
      } 
     } 

}); 

私はそれを自分で行う方法を学ぶが、私は打破し、助けを求める...イライラ取得しなければならなかった好きなので、これを理解しようとして時間を費やしてきた!

また、あなたのバインディングとアンバインドの.delegateを、それをajaxコンテンツの上に置かなければならないことも読んでいますか?私は.die()と.undelegate()を使って試しました...たぶんどこに配置するのか分かりません。

答えて

1

はそれがbindに何unbinddelegateにしundelegate

を見てみましょう。あなたのケースでは

、私はそれはのようなものだろうと思う:次に、あなたが関数内で$this.unbind('mouseup', handler);をドロップすることができ

$('#maindiv').undelegate("span.open", "mouseup").delegate("span.open", "mouseup" ... 

+0

$ this.click(ハンドラ)はどこに行きませんか。ありますか? $( '#maindiv')。undelegate( "。open"、 "mouseup"); – Brandon

+0

コードを徹底的に見ていないという罪悪感!しかし、あなたはevry ajaxコールの成功でそれを行う必要はありません。一度DOMを準備しておけば、ajaxを介して追加された新しいコンテンツは正しく接続されます。私はあなたのコードを取って、それをちょっとした形で見分ける必要がありますが、あなたはそのアイデアを得ます。 – Mrchief

+0

チーフチーフ、$ this.unbind( 'mouseup'、ハンドラ)を配置する必要があります。私はthis.click(ハンドラ)を持っていた同じ場所またはajax呼び出しの上に;機能が完璧に働いていたとき.bind( "mouseup ... – Brandon

関連する問題