簡體   English   中英

使用.removeAttr('checked')不起作用

[英]Using .removeAttr('checked') does not work

我使用codeigniter.see: 代碼示例,請填寫文本框並選中復選框,然后單擊添加的鏈接,看看自己不起作用.removeAttr('checked')

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


完整代碼:

$(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();
        });
    });
});

尊重地

您應該通過以下方式使用prop函數:

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

嘗試這個:

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

我認為刪除attr后設置值是錯誤的。

我最好這樣做:

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

復選框的checked狀態與元素是分不開的。 您再也無法刪除其HTML-element-ness,因此無法刪除其is-checked / is-not-checked狀態。 相反,請指示應取消選中該復選框。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM