相同类的克隆元素上的Click事件 [英] Click event on cloned element of same class

查看:93
本文介绍了相同类的克隆元素上的Click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当连续按下一个按钮时,我正在克隆一行.该行包含被按下的按钮,因此在克隆时,下面会添加一个新行,这意味着还有另一个按钮.该按钮状态为添加",但在按下添加按钮后变为删除".我遇到的问题是我希望click()函数检查按钮/类的最后一个实例,但是它仍然检查原始按钮.我希望它检查最后一个按钮.

I am cloning a row when a button is pressed in a row. The row contains the button being pressed, therefore when cloned a new row is added below, meaning there is another button. The button states "Add" but changes to "Remove" when add is pressed. The problem I'm having is that I want the click() function to check the last instance of the button/class, instead but it remains checking the original button. I want it to check the last button.

看看jsfiddle看看我要做什么:

Take a look at the jsfiddle to see what I am trying to do:

http://jsfiddle.net/Fogest/4gdJk/

我的问题不是将按钮的名称更改为删除",但我想知道如何将单击功能应用于添加的最后一个按钮?

My issue is not changing the name of the buttons to "Remove", but I want to know how should I be applying this click function to the last button that is added?

使用jQuery v1.6.1

Using jQuery v1.6.1

推荐答案

使用.on代替.click,这里是文档

$(document).on("click", ".add-remove-new:last", function () {
    $('tr.newService:first').clone().insertAfter($('tr.newService:last'));
});

工作演示

或者您可以将.live用于jquery 1.6.1

or you can use .live for jquery 1.6.1

$('.add-remove-new:last').live('click', function() {
    $('tr.newService:first').clone().insertAfter($('tr.newService:last'));
});

演示1.6.1版

这篇关于相同类的克隆元素上的Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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