功能绑定和克隆()函数 - jQuery的 [英] function binding and the clone() function - Jquery

查看:103
本文介绍了功能绑定和克隆()函数 - jQuery的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的KEYUP问题克隆元素时绑定。这里的情景:

I have problems with my keyup binding when cloning an element. Here's the scenario:

我有一个HTML标记是这样的:

I have an html markup like this:

<tr class="rijbasis">
   <td>
      <input type="text" class="count" />
   </td>
   <td>
       <span class="cost">10</span>
   </td>
   <td>
       <span class="total">10</span>
   </td>
</tr>

我绑定的KEYUP功能,这样我的表行的输入元素:

I'm binding an keyup function to the input element of my table row like this:

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

我设计这样的功能,所以我可以克隆一个onclick事件表行,并追加到TBODY:

I designed the function like this so I could clone the table row on a onclick event and append it to the tbody:

$('.lineadd').click(function(){
        $('.contract tbody').append($('.contract tbody tr:last').clone());
        $('.contract tbody tr:last input').val("0");
 });

这个人的作品,但对克隆行的投入要素的KEYUP功能不工作。

This al works , but the keyup function doesnt work on the input elements of the cloned row..

任何人都可以帮助或建议?我希望我是不够清楚,我会在必要时解决这一问题确实地添加细节。

Can anybody help or advice? I hope I was clear enough and I'll be surely adding details if needed to solve this problem.

问候

推荐答案

您有两个的真正的选项


  • 使用 克隆(真) 这也将克隆绑定事件处理程序

  • 使用事件)代表团生活(,以便将事件处理程序绑定到父元素,而新添加的行会得到相同的功能

  • 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

这篇关于功能绑定和克隆()函数 - jQuery的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆