2016-10-20 6 views
0

私は自分のコードで爽快な問題を抱えていましたが、私は見つけた解決策を見つけようとしましたが、成功しませんでした。ここでjqueryで削除した後の既存の要素

が私のコードです:

$(document).on("click",'.supact',function() { 
     $(this).parent().slideUp("slow", function() { 
      $(this).remove(); 
     }); 
     var num = 1; 
     $(".sact").each(function() { 
      alert($(this).attr("id")); 
      $(this).attr("id", "pact" + num); 
      num++; 
     }); 
     return false; 
    }); 

要素の親が削除されると(それはdiv要素だ)私は前に2 div要素を持っていた場合、それは1つだけのdivのidを私に警告するだろうが、それは私に警告1回ではなく2回。

あなたはどう思いますか?

ありがとうございました。

答えて

0

最後に、何が間違っていたかを見つけました。

<script type="text/javascript"> 
     $(document).on("click",'.supact',function() { 
      $(this).parent().slideUp("slow", function() { 
       $(this).remove(); 
       var num = 1; 
       $(".sact").each(function() { 
        $(this).attr("id", "pact" + num); 
        $(this).children('select').each(function() { 
         $(this).attr("id", "formact_id_value_liste" + num); 
         $(this).attr("name", "act_id_value_liste" + num); 
        }); 
        $(this).children('label').each(function() { 
         $(this).attr("for", "formact_id_value_liste" + num); 
        }); 
        num++; 
       }); 
      }); 
     }); 
</script> 

はまた、私はラベルを変更するためのコードを追加しました:)

関連する問題