简体   繁体   中英

Not empty value a input after add new input

I have two input in example and after add new input remove(or empty) values they now want not remove value a input, how is it?

Example: http://jsfiddle.net/3SmyE/

my try:

$clone.find('input').not(':has(name="family_un[]")').val('');

Full js code:

$(function () {
    $('a.add_input').live('click', function (event) {
        event.preventDefault();       
        var $this = $(this),
            $div = $this.closest('.add_units'),
            $clone = $div.clone().hide().insertAfter($div).fadeIn('slow');
        $clone.find('.adda').not(':has(.remove_input)').append('<div class="mediumCell"><a href="" class="remove_input"></a></div>');
        $clone.find('input').not(':has(name="family_un[]")').val('');
        $this.remove();
        console.log($('.add_units:last input:checkbox').prop('name'));
    });   
});

After applying my knowledge of cryptography, I've found the solution to your question.
Fiddle: http://jsfiddle.net/3SmyE/1/

Your current code:

$clone.find('input').not(':has(name="family_un[]")').val('');

Fixed code:

$clone.find('input').not('[name="family_un[]"]').val('');

The :has() pseudo-selector which selects child elements of the preceding selector. To select attributes, you have to suround the attribute by square bracelets, in the following format:
[attribute="value"] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM