Javascript Keyup事件不使用jquery生成的字段
我用jquery动态生成了一个表数据。最初,当我使用php时,keyup事件运行良好,我能够在T.Amount列中找到表中每行的.qestimate和#number_of_house的乘积,但现在它不工作了,代码清单 Html: //我正在调用但不工作的函数Javascript Keyup事件不使用jquery生成的字段,javascript,jquery,Javascript,Jquery,我用jquery动态生成了一个表数据。最初,当我使用php时,keyup事件运行良好,我能够在T.Amount列中找到表中每行的.qestimate和#number_of_house的乘积,但现在它不工作了,代码清单 Html: //我正在调用但不工作的函数 function multInputs() { var mult = 0; $("tr.tg-even").each(function() {
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);
});
}
})使用委托:
$(document).on('keyup', '.tg-even input', function(e){
// ...
});
或者,如果您愿意:
$(document).on('keyup', '.tg-even input', multInputs);
电话:
在real project中创建动态字段后,我们不应该直接将委托触发器添加到文档中,或者如果您有其他地方可以输入一些文本,那么性能就是一个问题。就这样,
$('.tg-even').on('keyup', 'input', function(e){
// ...
});
$(document).on('keyup', '.tg-even input', function(e){
// ...
});
$(document).on('keyup', '.tg-even input', multInputs);
$(".tg-even input").keyup(multInputs);
$('.tg-even').on('keyup', 'input', function(e){
// ...
});