我想取消选中所有具有特定类的复选框,但只检查一个特例。如何从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);
}
}
}
上面的代码将取消选中包括刚刚选择的所有“cheese_toppings”。我不想再重新检查刚刚选择的或将要召回的事件。
我认为最好的解决方案是从$('input:checkbox.cheese_toppings')
返回的列表中删除“checkboxElement”,然后将.attr('checked', false)
设置为该列表。但我不知道如何从列表中删除checkboxElement。
Oooh,我不知道输入:type语法...哪里有记录? – 2012-01-06 20:41:27
@GeorgeMauer嗨乔治,它的问题来源于代码,但它***被记录在这里:http://api.jquery.com/checkbox-selector/ :) – Paulpro 2012-01-06 20:44:38
@GeorgeMauer Note ':checkbox'选择器仅适用于jQuery。它不是一个CSS选择器。这里有一个完整的jQuery选择列表:http://api.jquery.com/category/selectors/ – Paulpro 2012-01-06 20:45:31