开发者

Here are the problems, with a small jQuery script(add input)

开发者 https://www.devze.com 2023-03-26 17:14 出处:网络
how can empty value input new. in input new not putting value and it is empty and value putting in input previous, no in input new. how is it?

how can empty value input new. in input new not putting value and it is empty and value putting in input previous, no in input new. how is it?

For results, please fill out the input and clicked on add: JSFIDDLE

$(function () {
        $('a.add_input').live('click', function (e) {
            e.preventDefault();
            var $mediumCell = $(this).closest("div.mediumCell");             
            var $class =  '.' + $(this).closest('div.find_input').find('div').attr('class');
            var $column = $(this).closest($class);
            var input = $column.clone().wrap("<div />").parent().html();
            //var find = $(this).closest($class);    
            //var clone = find.find('.mediumCell:first').clone();
            //find.find('.mediumCell:has("input"):last').after(clone);

            alert(input)
            $column.before($(input));
            $($class+' .add_input').remove();
            $($mediumCell).append('<a href="" class="remove_input"></a>');
            $($mediumCel开发者_如何学Pythonl).append('<a href="" class="add_input"></a>');
        });
        $('.remove_input').live('click', function (e) {
            e.preventDefault();
            var $class =  '.' + $(this).closest('div.find_input').find('div').attr('class');
            $(this).parents($class).remove();
            $($class+' .adda:last').append('<a href="" class="add_input"></a>');
        });
    });


I think it will be better if you make a template of the repeated part instead of getting it from the html directly

I updated your code with a template div and when you click add I get its html and append it to main html

check it here

you can use the same idea for the second text input

0

精彩评论

暂无评论...
验证码 换一张
取 消