"如果x〃;工作-“;如果x或!y”;不起作用

"if !x" working - "if !x or !y" not working

本文关键字:如果 不起作用 工作 quot      更新时间:2023-09-26

我需要在jquery脚本中排除两个容器,使其不选中其中的复选框,所以我制作了一个if:

$('#newform li :checkbox').change(function() {
    var exclude = $(this).closest('div');
    if (!exclude.hasClass('size') || !exclude.hasClass('price'))
        $(this).closest('ul').find(':checkbox').not(this).prop('checked', false);
});

现在并不是"排除"任何内容,但如果我从if中删除||,它将适用于唯一的类。问题出在哪里?

使用

if ($('#your_element').is('.size, .price')) {
    $(this).closest('ul').find(':checkbox').not(this).prop('checked', false);
}

这将针对多个类进行检查。