jquery按类型查找子项

时间:2014-06-16 21:48:00

标签: jquery pug

我有一个有几行的表,每行有三列,第一列有一个复选框,第二列有输入框,第三列有一个按钮,我需要先找到每一行,然后再根据该行的复选框,从同一行的文本框中获取文本。但我有问题找到复选框和输入框,

我的玉页是:

 table.mapping
 tbody
                     tr
                         td
                           input.checkbox(class='action', type='checkbox',name='event_name')
                                   Name
                         td
                                input.vendor-name.input(type='text')
                                  
                         td
                                  
                                input(id='filePath', type='file')
                                span.fileLocation

我的jquery代码:

rows = $(@el).find('.mapping tbody tr')
for row in rows
  checkbox = row.find('td input.checkbox')  <-- complained here:undefined is not a function
  if (checkbox.checked)
    name = row.find('td input')

我也尝试过row.find(&#39; .checkbox&#39;),它也没有用。谁有人可以帮忙?谢谢!

1 个答案:

答案 0 :(得分:0)

如果您正在使用实际的for in循环,那么您将迭代返回的jQuery对象的属性,而不是jQuery类数组对象中的元素。

相反,您应该使用$(@el).find('.mapping tbody tr').each(function(idx, el) { ... })并在引用$(this)的位置处理您的逻辑。

checkbox = $(this).find('td input.checkbox');
if (checkbox.checked)
    name = row.find('td input')
相关问题