我已經動態生成了jQuery的表數據。最初,當我用php做的keyup事件工作完美時,我能夠在T.Amount列中找到.qestimate和#number_of_houses產品的每一行,但現在它不工作,代碼列表Keyup事件不能與jQuery生成的字段
HTML:
<table class="tg tg-table-light-1" border="">
<thead>
<tr>
<th>No.</th>
<th>Material</th>
<th>Qty</th>
<th>T. Amount</th>
</tr>
</thead>
</table>
JQuery的:
$(document).ready(function() {
table=$('.tg-table-light-1');
$.getJSON("<?php echo base_url() . 'material_estimation/loadEstimates' ?>/", function(materialdetails) {
i=1;
$.each(materialdetails , function(i, materials){
newmaterials= materials.Materials;
sanitized_newmaterials=newmaterials.replace(/<\/?([a-z][a-z0-9]*)\b[^>]*>?/gi, '');
data="<tr class=\"tg-even\">
<td class=\"\">"+i+"</td>\n\
<td class=\"tg-even\">"+sanitized_newmaterials+"</td>\n\
<td class=\"\"><input type=\"text\" style=\"width:40px; text-align: center;\" class=\"qestimate\" name=\"qestimate[]\" value=\""+materials.Quantity_estimate+"\"/></td>\n\
<td class=\"\"><input type=\"text\" style=\"width:40px; text-align: center;\" class=\"tqty\" name=\"tqty[]\" value=\""+materials.total_quantity+"\"/></td>\n\
</tr>";
table.append(data);
i++;
});
});
//觸發事件
$(".tg-even input").keyup(multInputs);
//我打電話,但沒有工作
function multInputs() {
var mult = 0;
$("tr.tg-even").each(function() {
// get the values from this row:
var $val1 = $('#number_of_houses option:selected').val();
var $val2 = $('.qestimate', this).val();
var $total = ($val1 * 1) * ($val2 * 1);
var qty = $('.tqty', this).val($total);
});
}
})