如何从jQuery选择器返回的列表中删除元素?

Jus*_*tin 0 javascript jquery

我想取消选中具有特定类的所有复选框,但刚刚选中的复选框除外.

function PizzaToppings_OptionValueChanged(checkboxElement) {
    if ($(checkboxElement).attr("checked")) {
        if($(checkboxElement).hasClass('cheese_toppings'))
        {
            // This will uncheck all other "cheese_toppings" but I want the newly selected item "checkboxElement" to remain checked.
            $('input:checkbox.cheese_toppings').attr('checked', false);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码将取消选中所有"cheese_toppings",包括刚才选择的那个.我不想重新检查刚刚选择的那个或者将召回事件.

我认为最好的解决方案是从返回的列表中删除"checkboxElement" $('input:checkbox.cheese_toppings'),然后将其.attr('checked', false)设置为该列表.但我不确定如何从列表中删除checkboxElement.

Pau*_*aul 6

$('input:checkbox.cheese_toppings').not(checkboxElement).attr('checked', false);
Run Code Online (Sandbox Code Playgroud)

请参阅jQuery文档:.not()