我有一个表,其行由ajax查询响应生成,如:
var inp = '<input id="new_po_qty" style="text-align:center" type="text" value="1">';
$('<tr id="new_po_item_row">').html('<td style="text-align:center">' + sku_id + '</td><td style="text-align:center">' + inp + '</td><td id="new_po_cp" style="text-align:center">' + cost_price + '</td><td id="new_po_total_cp" style="text-align:center">' + cost_price + '</td>').appendTo('#new_po_body');
现在我写了一个jquery函数来捕获表行中inp
变量的变化。但是jquery函数没有捕获我在输入框中所做的更改。
Jquery函数:
$('#new_po_qty').on('change paste', function(){
alert('changes made.');
$.niftyNoty({
type:"primary",icon:"",title:"Start Adding Products.",container:"floating",timer:5000
});
});
我的功能是什么?
答案 0 :(得分:2)
使用事件委托:
$(document).on('change paste', '#new_po_qty', function(){
alert('changes made.');
$.niftyNoty({
type:"primary",icon:"",title:"Start Adding Products.",container:"floating",timer:5000
});
});