tr.append($("<td/>").html('<input type="text" name="unit_price" id="unit_price"/>'));
这是我动态生成的文本框,我已经尝试了很多像下面这样的解决方案,但它不起作用帮助我极客
$("#unit_price").live("keyup", function(){
//Your Code to handle the click.
});
$(staticAncestors).on(eventName, dynamicChild, function() {});
最佳答案
您需要使用event delegation 。
Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.
$("body").on("keyup","#unit_price", function(){
//Your Code to handle the click.
});
关于jquery - 动态生成文本框的按键事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27943052/