1

apologies for question title not making too much sense.

I am trying to pass the checkbox from the current row to another function where that function checks if it is checked or not and performs accordingly.

I have a table with several rows, and when changing an input qty I want the current row and checkbox name/id to be passed to another function.

you can see the example here

The html in this fiddle is what is generated by my php page onload.

I can get the onchange to fire but the checkbox for that row is always unchecked. I think this is because var cb = $(this).siblings('input[name^="treated"]'); is not passing the correct object to the next function.

I did get some assistance from @pXL previously with this fiddle but whilst it works in this example, cant get it to work with my generated html.

so when changing qty, I want alert 1 to fire if the checkbox treated is checked for that specific row. if it is not checked then alert 2

Thanks in advance.

4

1 回答 1

1
var cb = $(this).siblings('input[name^="treated"]');

应该是

var cb = $(this).closest('tr').find('input[name^="treated"]');

在这种siblings情况下将不起作用,因为input[name^=treated]它不是数量输入的兄弟。

兄弟元素是与其他元素处于同一级别的元素。

但是这里的treated输入在另一个里面td和不一样td

检查小提琴

于 2013-06-27T19:17:46.577 回答