Jquery 动态生成的文本框的按键事件

Jquery 动态生成的文本框的按键事件,jquery,dynamic,Jquery,Dynamic,您需要使用 事件委派允许我们将单个事件侦听器附加到父元素,该事件侦听器将为与选择器匹配的所有子体触发,无论这些子体现在存在还是将来添加 使用这个 $("body").on("keyup","#unit_price", function(){ //Your Code to handle the click. }); 试试这个.. $(document).on("keyup","#unit_price", function(){ //Results here }); $(文档)

您需要使用

事件委派允许我们将单个事件侦听器附加到父元素,该事件侦听器将为与选择器匹配的所有子体触发,无论这些子体现在存在还是将来添加


使用这个

$("body").on("keyup","#unit_price", function(){  
 //Your Code to handle the click.
}); 

试试这个..

$(document).on("keyup","#unit_price", function(){  
 //Results here
}); 

$(文档).ready(函数(){
$(“.test”).append($(“”).html(“”));
$(“#单价”).keyup(函数(){
警报($(this.val());
});
});

演示:

live
已被弃用。看见
$("body").on("keyup","#unit_price", function(){  
 //Your Code to handle the click.
}); 
$(document).on("keyup","#unit_price", function(){  
 //Results here
}); 
<table >
    <tr>
        <td class="test"></td>  

    </tr>
</table>

$(document).ready(function(){

$(".test").append($("<td/>").html('<input type="text" name="unit_price" id="unit_price"/>'));
     $("#unit_price").keyup(function(){
alert($(this).val());
  });
});