イベントが添付されている可能性のある入力フィールドを含むテーブルの最後の行を複製しようとしています (この場合は keyup イベントです)。また、入力フィールドの id を変更して、次のような行を反映させます。
テーブル[0].フィールド1、テーブル[0].フィールド2...テーブル[1].フィールド1...など
問題は、行を追加してイベントも取得できることです。新しいクローン入力に書き込むと、イベントが開始されます。ただし、作成された最初の行のみ。新しいものを作成すると、入力を含む行が正しくレンダリングされますが、イベントはレンダリングされません。メソッドは次のとおりです。
addRow= function(tableid){
//jquery selector get table tbody with id
var table=jQuery('table[id="'+tableid+'"] >tbody');
//get last row containing input fields with tr class hoverTransparente
var lastRow=jQuery('table[id="'+tableid+'"] > tbody > tr:last');
//make a clone of the row
var clones = lastRow.clone(true); // copy events/children too
//get the input fields from the cloned row
var clonedInPuts=clones.find('input');
//for each input
jQuery(clonedInPuts).each(function (){
//set new input val to empty
jQuery(this).val("");
var inputId=jQuery(this).attr('id');
//table id
var table=inputId.split("[")[0];
//column id
var tableField=inputId.split(".")[1];
var idnumber=inputId.indexOf("[")+1;
//convert to number to make addition for new id index
var number = Number(inputId.charAt(idnumber))+1;
//replace id index with incrementaed value
var newId=inputId.replace(inputId.charAt(idnumber),number);
//change id for new one
jQuery(this).attr('id',newId);
//check if this variable exists/is not undefined
if(window["elements_"+table+"_"+tableField]){
window["elements_"+table+"_"+tableField].push(jQuery(this).get(0));
}
});
clones.appendTo(table);
}
何か案は?クロムでデバッグしようとすると、入力要素の domtree からのイベント onkeyup が null になりますが、jquery を直接使用して選択し、.data('events') メソッドを取得すると、入力フィールドにイベントが添付された配列が返されます. onkeyup は null とは異なるものを返すべきではありませんか?