2011-07-21 11 views
1

私はセル数量を持つデータグリッドを持ち、別の価格は結果を示すラベル(価格* qty)を末尾に付けます。それは完全に仕事です。しかし、私は行を削除することもできますし、それは動作を停止します。 JQuery //削除後IDイベントトリガーなし

  • その後削除(あなたが価格* 数量の結果が表示されます)

    1. は、各列に数値を入力します。

      この

      は、問題を再現するために私のコード

      http://jsfiddle.net/bizonbytes/SYwpy/24/

      です行2

    2. 今すぐ行1に行き、 の値を変更すると、結果を確認しますが、行3で実行すると、 が実行されません。

    なぜ私は3行目が機能しなくなったのですか。

    Iは1と2にIDの名前を変更する必要があるビジネスREQとして

    とHTMLは1と3

    にそれらを残していない:

    <div class="row_table row_service_table" id="service_row_1"> 
        <div class="cell celldata cell_service_data"><input type="text" class="quantity_row" id="quantity_row_1" rel="1"/></div> 
        <div class="cell celldata cell_service_data"><input type="text" class="price_row" id="price_row_1" rel="1"/></div> 
        <div class="cell celldata cell_service_data"><a href="javascript:void(0)" class="delete_service_row" id="delete_service_row_1" rel="1">Delete row 1</a></div> 
        <div class="cell celldata cell_service_data">Result row 1=<span id="total_1"></span></div> 
    </div> 
    
    etc. 
    

    Javascriptを:

    $(".delete_service_row").click(function(){ 
        var rowId = $(this).attr('rel'); 
    
        $('#service_row_' + rowId).remove(); 
    
        // iterates through each of the elements matched by the selector 
        $('.row_service_table').each(
         // i represents the index of each of the elements 
         function(i){ 
           // sets the id of each of the returned elements 
           // to the string concatenated with the expression 'i + 1' 
          this.id = 'service_row_' + (i+1); 
    
          $(this).children('.cell_service_data').children('.quantity_row').attr('id', 'quantity_row_' + (i+1)); 
          $(this).children('.cell_service_data').children('.quantity_row').attr('rel', (i+1)); 
          $(this).children('.cell_service_data').children('.quantity_row').attr('name', 'quantity_row_' + (i+1)); 
    
          $(this).children('.cell_service_data').children('.price_row').attr('id', 'price_row_' + (i+1)); 
          $(this).children('.cell_service_data').children('.price_row').attr('rel', (i+1)); 
          $(this).children('.cell_service_data').children('.price_row').attr('name', 'price_row_' + (i+1)); 
         }); 
    }); 
    
    $('.quantity_row,.price_row').live('change', function(){ 
        var rowId = $(this).attr('rel'); 
    
        // Lets update the total line 
        var total = parseFloat($('#quantity_row_' + rowId).val()) * parseInt($('#price_row_' + rowId).val()); 
        $('#total_' + rowId).text(total); 
    }); 
    
  • +0

    リンクは優れていますが、[関連するコードを質問に含めてください](http://stackoverflow.com/questions/how-to-ask)も常に覚えておく必要があります。 (私はあなたのためにこれをやった。) –

    答えて

    1

    2入力のうちidrelが再マッピングされますが、結果の範囲のidはそのままです! (含まれているテキストも変更されていませんdiv

    です。

    変化があった:

    1. 結果行に<span class="rezLabel">を添加し、結果値がrezValueのクラスにまたがる与えました。
    2. はにリナンバリングコードを変更:

      $('.row_service_table').each (
          // i represents the index of each of the elements 
          function(i){ 
            // sets the id of each of the returned elements 
            // to the string concatenated with the expression 'i + 1' 
           this.id   = 'service_row_' + (i+1); 
           var baseNode = $(this).children('.cell_service_data'); 
      
           baseNode.children('.quantity_row').attr('id', 'quantity_row_' + (i+1)); 
           baseNode.children('.quantity_row').attr('rel', (i+1)); 
           baseNode.children('.quantity_row').attr('name', 'quantity_row_' + (i+1)); 
      
           baseNode.children('.price_row').attr('id', 'price_row_' + (i+1)); 
           baseNode.children('.price_row').attr('rel', (i+1)); 
           baseNode.children('.price_row').attr('name', 'price_row_' + (i+1)); 
      
           baseNode.children('a').text('Delete row ' + (i+1)); 
           baseNode.children('a').attr('id', 'delete_service_row_' + (i+1)); 
           baseNode.children('a').attr('rel', (i+1)); 
      
           baseNode.children('.rezLabel').text('Result Row ' + (i+1) + ' = '); 
           baseNode.children('.rezValue').attr('id', 'total_' + (i+1)); 
      }); 
      
    +0

    ようこそ。喜んで助けてください。 –

    0

    行を削除すると、idとも変更されます複数のオブジェクトの属性。あなたはそれをする必要はありません。 $('.row_service_table').eachブロックを削除しても問題ありません。

    0

    あなたは、それが識別子をリセットする必要はありません)(削除呼び出した後!私はフィドルを更新しました。

    1

    each()のID total_3total_2の名前を変更する必要があります。変更イベントは、total_2スパンを更新しようとしましたが、存在しません。total_1とのみが存在します。

    関連する問題