开发者

help me for add input in jQuery

i have tow input, style column and mediumCell. i want first input only have add, not add and remove together. also each input except first i开发者_如何学Gonput have remove link and last input have add and remove together.

code: http://jsfiddle.net/cJACG/15/


This might help:

$(function () {
            $('a.add_input').live('click', function (event) {
                event.preventDefault();
                var newDiv = $('.ai_service').find('div:first').clone();
                newDiv.append('<a href="" class="remove_input">remove</a>')
                newDiv.find('input').each(function () { $(this).val(''); });
                $('div.ai_service:first div:last').before(newDiv);
            });

            $('a.remove_input').live('click', function (event) {
                event.preventDefault();
                $(this).closest('div').remove();
            });
        });


Assign a empty value to the cloned input:

var input = $column.clone().val('').wrap("<div />").parent().html(); 


Instead of cloning and appending, you can insert and remove nodes before or after siblings:

 $('a.add_input').click(function() {
        $('a.remove_input').before('<input type="text" name="service[]" style="width: 155px;" placeholder="خدمات دیگر" title="خدمات دیگر" />');
    });

A simplified version of your code can then be written thus.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜