使用jQuery删除DOM节点

时间:2015-12-13 11:59:52

标签: jquery html

我需要删除单击删除链接时插入的2个字段 我只能删除一个。

$(document).ready(function() {

    var max_fields      = 25; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div class="col-md-6"><input type="text" class="form-control" name="mytext[]"/></div>'); //add input box
            $(wrapper).append('<div class="col-md-6"><input type="text" class="form-control" name="mytext2[]"/><a href="#" class="remove_field">Remove</a></div>');

        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })

});

1 个答案:

答案 0 :(得分:0)

这可能会帮助你.......

String[] yourStringArray = yourString.split("regularExpression");
//here regular expression is the character by which you will split string