function binding and the clone() function - Jquery

こ雲淡風輕ζ 提交于 2019-12-01 09:06:49

You've got two real options

  • use clone(true) which will also clone the bound event handlers
  • use event delegation with live() so that the event handler is bound to a parent element and thus newly added rows will get the same functionality

Use jQuery's live events; this way the handler will automatically be bound to newly created elements (such as the clones in your example).

For example:

$('.rijbasis input').live('keyup', function()
{
    var parent = $(this).parent().parent();
    $('.total',parent).text(parseInt($('.cost',parent).text()) * parseInt($('.count',parent).val()));
}

Use .live instead of .keyup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!