2016-08-03 4 views
1

jqueryを使用して新しいテーブル行を動的に追加しています。それは正常に追加され、今私はドロップダウンの値に応じて各レコードを動的に取得し、複数のdivに表示したい。テーブル行が1つだけの場合はすべて正常に動作しますが、jqueryを使用して新しい行を追加すると、カウンタ値が暗くなりません。これは、seconf行からドロップダウン値を選択するとレコードを取得しません。新しいフィールドを追加したときのGeneateの動的値

答えて

0

クリックすると、このメソッドが呼び出され、変数が常に2で初期化されます。それは良い習慣ではありません。次のようにすることができます。 function add_allowance(){

var click; 
    jQuery("#addrows").click(function(){ 
     jQuery('#maintable tr:last').after('<tr class="tablechild"><td><select name="empallownacename" id="allowancename" class="select2_category form-control"><option value="none" selected="selected">-Select-</option></select></td><td><input type="text" name="empmount" value="" class="form-control" /></td><td><input type="text" name="empdescription" value="" class="form-control" /></td><td><a style="cursor: pointer;" value="Remove" class="minusbtn" id="remove"><i class="fa fa-trash-o"></i></a></td></tr>'); 
    }); 
    click=$('table tr).length; // It will count number of rows in the table and return integer value no of rows 
} 
関連する問題