删除的onclick元素(包括删除按钮本身)与jQuery [英] Remove elements onclick (including the remove button itself) with jQuery

查看:814
本文介绍了删除的onclick元素(包括删除按钮本身)与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些问题了至极的样子我的,但在这种情况下,我想删除按钮被除去,我不知道我可以做到这一点。

I know there are some questions up wich look like mine, but in this case i want the remove button to be removed as well and i dont know how i can do this.

下面是我的问题;

我追加与jQuery 3个元素被点击追加按钮时。
包括删除按钮。

I append 3 elements with jQuery when an append button is clicked. Including a remove button.

我想这个删除按钮来删除它自己和另外两个要素。
计数器应该相同编号的,但我不知道如果我没有使用jQuery这个正确的方式。

I want this remove button to remove it self and the other two elements. The counter should make identical Id's, but i'm not sure if i did this right way with jQuery.

如何删除三个要素,包括删除按钮的onclick?

How can i delete three elements including the remove button onclick?

$(function() {
var counter = 0;

  $('a').click(function() {
  $('#box').append('<input type="checkbox" id="checkbox" + (counter) + "/>');
  $('#box').append('<input type="text" id="t1" + (counter) + "/>');
  $('#box').append('<input type="button" value="." id="removebtn" + (counter) + "/>');
  $("#box").append("<br />");
   $("#box").append("<br />");
     counter++;
     });

$('removebtn').click(function() {
remove("checkbox");

});
});

感谢您提前

推荐答案

我的建议是这样的。

$(function () {
    var counter = 0;

    $('a').click(function () {
        var elems = '<div>'+
              '<input type="checkbox" id="checkbox"' + (counter) + '" class="item"/>' + 
              '<input type="text" id="t1"' + (counter) + '"/>' +
              '<input type="button" class="removebtn" value="." id="removebtn"' + (counter) + '"/>' +
        '</div>';
        $('#box').append(elems);
        $("#box").append("<br />");
        $("#box").append("<br />");
        counter++;
    });

    $('.removebtn').live(function () {
        $(this).parent().remove();   
    });
});

这篇关于删除的onclick元素(包括删除按钮本身)与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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