为`jQuery提供`removeID`,如`removeClass`

Léo*_* 준영 5 jquery

如何id通过jQuery 删除属性?

jQuery('a.no_flag_question').live('click', function(){
    jQuery.post('/codes/handlers/no_flag_question.php', 
        { question_id: jQuery(this).attr('rel') });
            $(".question_box").removeClass("yellow");   // problem here
            alert ("Question is now not spam.");
});
Run Code Online (Sandbox Code Playgroud)

此代码应删除以下黄色 - 属性

<div id="yellow" class="question_box">
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用.原因很可能是这个功能removeClass.我显然使用了错误的功能,因为我想使用ID.

med*_*iev 15

$('.question_box').removeAttr('id')
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请访问http://docs.jquery.com/Attributes/removeAttr


hob*_*bbs 6

removeClass只存在,因为它class是一个多值属性...如果你有一个<div class="one two three">并且你调用.removeClass("two")它,它应该最终得到class="one three".addClass并且removeClass存在是为了避免你自己完成所有这些工作.id这种方式并不特别,所以你只需要访问它attr.