开发者

Using .removeAttr('checked') does not work

I use of codeigniter.see you:example of my code please fill textbox and checked checkbox next clicked on link add, see yourself that not work .removeAttr('checked')

newDiv.find('input').each(function () { $(this).removeAttr('checked').val(''); });

full code:

$(document).ready(function () {
    $(function () {
        $('a.add').live('click', function (event) {
            event.preventDefault();
            var $class = '.' + $(this).closest('div.find_input').find('div').attr('class');
            var newDiv = $(this).closest($class).clone();
            $(this).closest($class).find('.adda').remove()
            //$(this).find('.adda').remove()
            //newDiv.append('<a href="" class="remove_input"></a>')
            newDiv.find('input').each(function () {
                $(this).removeAttr('checked').val('');
            });
            $($class + ':last').after(newDiv);
            //newDiv.remove('.adda')
            //alert(newDiv)
        });

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

With respe开发者_如何学Goct


You should be using the prop function, by doing this:

$(this).prop('checked', false);


Try this:

newDiv.find('input').each(function () { $(this).prop('checked', false).val(''); });


I think it's a mistake to set the value after removing the attr.

I've had better luck doing this:

$(this).attr('checked', false);

A checkbox's checked state is inseparable from the element; you can no more remove its is-checked/is-not-checked state than you can remove it's HTML-element-ness. Instead, indicate that the checkbox should be unchecked.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜