找到你要的答案

Q:How to filter checkboxes using JQuery 2.1.4?

Q:如何使用jQuery 2.1.4滤波器复选框?

I am trying to select and de-select all check boxes given in table column. I have already done code for JQuery version 1.4.0 but, after upgrading version to 2.1.4 it has stopped working.

The problem where I am getting in my code is here:

function findCheckBoxes(selectid, table) {
    return $(table).find('td input:checkbox:not(:disabled):[id*=' + selectid + ']');
}

It is throwing error:

Uncaught Error: Syntax error, unrecognized expression: td input:checkbox:not(:disabled):[id*=chkselect]

If I remove the further filter from the find function then it works fine but, I also want to filter the disabled and specific column checkboxes.

function findCheckBoxes(selectid, table) {
    return $(table).find('td input:checkbox');
}

But, It selects all checkboxes not from particular column.

Here is my fiddle

我试图选择和取消选择表列中给出的所有复选框。我已经为jQuery版本1.4.0做代码但是,升级后的版本2.1.4已停止工作。

我在这里输入代码的问题就在这里:

function findCheckBoxes(selectid, table) {
    return $(table).find('td input:checkbox:not(:disabled):[id*=' + selectid + ']');
}

这是投掷错误:

Uncaught Error: Syntax error, unrecognized expression: td input:checkbox:not(:disabled):[id*=chkselect]

如果我从中找到很好的工作但功能将进一步过滤,我也想过滤禁用特定列的复选框。

function findCheckBoxes(selectid, table) {
    return $(table).find('td input:checkbox');
}

但是,它选择复选框不从特定的列。

这是我的小提琴

answer1: 回答1:

The problem is the : before [id*= which creates an invalid selector

$(table).find('td input:checkbox:not(:disabled)[id*=' + selectid + ']');

Demo: Fiddle

问题是:在创建一个无效选择器之前

$(table).find('td input:checkbox:not(:disabled)[id*=' + selectid + ']');

演示:小提琴

javascript  jquery