.parent()。remove()问题 [英] .parent().remove() issue

查看:359
本文介绍了.parent()。remove()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于jQuery的表单,您可以在应用程序中添加额外的人员。我克隆了第一个字段集,并将其添加到最多3个额外的人。当你添加了一个额外的人时,你可以选择删除该人。

但是,我的删除按钮不起作用。早些时候,直到我将额外的函数添加到克隆来更改字段集中其他元素的ID。



我正在使用:

  $(。remove)。click(function(){
$(this).parent()。remove();

原本是在工作,但现在不是,我不知道为什么。



我已经取消了停止第一个'删除此人'的行,只是为了表明第一个仍然有效,其余部分没有。(我将定位第一个关闭阶段最终是固定的)



可能更容易看到它,所以我把它放在这里 http://bit.ly/kHcAbe



因此,从本质上讲,为什么我的'删除此人'除了第一部分之外的所有内容都可以工作吗?

解决方案

试试:

  $(document).on('click','.remove',func和(){
$(this).parent()。remove();
});

事件在页面加载时绑定,因此新添加的元素不是。


I have a jQuery-based form where you can add extra people to the application. I'm cloning the first fieldset and adding it onto the end up to a max of 3 additional people. When you've added 1 extra person then you have the option to remove that person.

However, my remove button isn't working. It was, earlier, until I added the extra functions to the cloning to change the ids of other elements within the fieldset.

I'm using:

$(".remove").click(function() {
    $(this).parent().remove();

which was working originally but now it's not and I can't figure out why.

I've taken out the lines that stop the first 'delete this person' just to show that the first one still works but the rest don't. (I'll be positioning the first one off stage eventually when it's fixed)

Probably easier to see it so I put it up here http://bit.ly/kHcAbe

So essentially, any ideas why my 'delete this person' isn't working on everything but the first section?

解决方案

Try:

$(document).on('click', '.remove', function() {
    $(this).parent().remove();
});

Events are bound on page load so newly added element aren't.

这篇关于.parent()。remove()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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