0

質問があります。助けていただけますか?

私は次のコードを持っています...

$("#ativ").each(function(){
      if(this.id){
        this.id = "ativ[" + counter +"]";
        ativ = $(this).attr("id");
        alert(ativ);
      }
    });

// This part is ok!
// Now I want to capture the onChange event of this new renamed id
// How do I do????
    $("#"+ativ).live("click",function() {
        alert('Hello world!');
    });

// This piece of code is not working!
4

2 に答える 2

0

ID が変更されるたびにイベント リスナーを更新する

$("#ativ").each(function(){
      if(this.id){
        this.id = "ativ[" + counter +"]";
        ativ = $(this).attr("id");

        // your listener here
        $("#"+ativ).click(function() {
          alert('Hello world!');
        });

      }
    });

-また-

クラスを使用してdivを識別します

于 2013-05-27T18:06:20.547 に答える
0

jQuery >= 1.7 を使用している場合は、メソッドを使用する必要がありますon()

元:

$("body").on("click", ativ, function(){
     alert('Hello world!');
});

公式ドキュメントを参照してください

于 2013-05-27T18:06:22.067 に答える