0

I have a table with a list of items, check boxes next to each item, and a button to delete checked items.

So I have this selector in jquery to delete the rows of the selected check boxes after coming back from an ajax call to delete the affected items:

tr input[name=storePurchaseItemIds\\[\\]][value=" + id + "]

I expected it to select all "tr" elements that have an input whose name is storePurchaseItemIds[] and have a value of the id variable.

Instead it seems to have done the opposite: Selected all inputs that are part of a row (when I called remove() on the result it removed the check boxes, leaving the rows in tact).

Clearly there is something I have misunderstood about selectors and am curious why the unexpected result happens.

4

1 回答 1

1

您在这里使用后代选择器,因此它选择输入元素,而不是您需要选择tr具有input匹配条件的元素的元素。所以使用:has().has()如下所示

$("tr:has(input[name=storePurchaseItemIds\\[\\]][value=" + id + "])")

或者

$("tr").has("input[name=storePurchaseItemIds\\[\\]][value=" + id + "]")
于 2013-09-30T15:40:04.620 回答