Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在表的第一行中选择输入_Jquery_Jquery Selectors_Html Table - Fatal编程技术网

Jquery 在表的第一行中选择输入

Jquery 在表的第一行中选择输入,jquery,jquery-selectors,html-table,Jquery,Jquery Selectors,Html Table,我正在处理的页面包含一个表,表中有一行标题、几行文本输入和一行总计。当用户在输入中输入数字时,将在总计行中计算每列的总和。此计算在触发输入的更改事件时运行 加载页面时,我希望能够在表的第一行中的文本输入上触发一个更改事件。我在找出正确的选择器时遇到了一些问题 表格结构示例: <table> <tr class="tblRow headerRow"> <!-- header cells --> </tr> <tr class

我正在处理的页面包含一个表,表中有一行标题、几行文本输入和一行总计。当用户在输入中输入数字时,将在总计行中计算每列的总和。此计算在触发输入的更改事件时运行

加载页面时,我希望能够在表的第一行中的文本输入上触发一个更改事件。我在找出正确的选择器时遇到了一些问题

表格结构示例:

<table>
  <tr class="tblRow headerRow">
    <!-- header cells -->
  </tr>
  <tr class="altTblRow">
    <td class="tableCell">
      <input type="text" id="input1-1">
    </td>
    <td class="tableCell">
      <input type="text" id="input1-2">
    </td>
    <td class="tableCell">
      <input type="text" id="input1-3">
    </td>
  </tr>
  <tr class="tblRow">
    <td class="tableCell">
      <input type="text" id="input2-1">
    </td>
    <td class="tableCell">
      <input type="text" id="input2-2">
    </td>
    <td class="tableCell">
      <input type="text" id="input2-3">
    </td>
  </tr>
  <tr class="tblRow">
    <td class="tableCell">
      <input type="text" id="input3-1">
    </td>
    <td class="tableCell">
      <input type="text" id="input3-2">
    </td>
    <td class="tableCell">
      <input type="text" id="input3-3">
    </td>
  </tr>
  <tr class="altTblRow totalRow">
    <!-- total cells -->
  </tr>
</table>
是否有一个选择器可以仅用于第一个表行中的输入,还是必须获取第一个输入并使用.parent获取行


注意:代码示例中的ID已更改;否则我会使用“input[class*=input1]”

我建议,尽管未经测试:

$('tr:not(".headerRow")').first().find('input').change();

此外,我建议修改HTML以利用语义,这将简化jQuery:

<table>
  <thead>
    <tr class="tblRow headerRow">
      <!-- header cells -->
    </tr>
  </thead>
  <tfoot>
    <tr class="altTblRow totalRow">
      <!-- total cells -->
    </tr>
  </tfoot>
  <tbody>
    <tr class="altTblRow">
      <td class="tableCell">
        <input type="text" id="input1-1">
      </td>
      <td class="tableCell">
        <input type="text" id="input1-2">
      </td>
      <td class="tableCell">
        <input type="text" id="input1-3">
      </td>
    </tr>
    <!-- other rows -->
  </tbody>
</table>

参考资料:

. . . .
尽管未经测试,我还是建议:

$('tr:not(".headerRow")').first().find('input').change();

此外,我建议修改HTML以利用语义,这将简化jQuery:

<table>
  <thead>
    <tr class="tblRow headerRow">
      <!-- header cells -->
    </tr>
  </thead>
  <tfoot>
    <tr class="altTblRow totalRow">
      <!-- total cells -->
    </tr>
  </tfoot>
  <tbody>
    <tr class="altTblRow">
      <td class="tableCell">
        <input type="text" id="input1-1">
      </td>
      <td class="tableCell">
        <input type="text" id="input1-2">
      </td>
      <td class="tableCell">
        <input type="text" id="input1-3">
      </td>
    </tr>
    <!-- other rows -->
  </tbody>
</table>

参考资料:

. . . .
您可以选择除最后一行之外的所有行:

$('tr:not(:last-child) input')

或者,如果您既不想要页眉,也不想要页眉:

$('tr:not(:last-child):not(:first-child) input')

您可以选择除最后一行之外的所有行:

$('tr:not(:last-child) input')

或者,如果您既不想要页眉,也不想要页眉:

$('tr:not(:last-child):not(:first-child) input')

插入使用表格行尝试whileparameter并尝试,然后查看得到的结果如果您得到明确的信息,请告诉我如果没有显示您得到的确切错误

插入使用表格行尝试whileparameter并尝试,然后查看得到的结果如果您得到明确的信息,请告诉我如果没有显示您得到的确切错误唯一的问题是,我试图只选择一行中的输入,因为该表最终将有几百个单元格,类似于一个15 x 25的表,如果我只对每列运行一个单元格,我不想让页面陷入大量计算的泥潭。但是,使用$'tr:not:last child:not:first child.first.find'输入可能有效。我来试一试。唯一的问题是,我试图只选择一行中的输入,因为该表最终将有几百个单元格,类似于一个15 x 25的表,如果我只对每列运行一个,我不想让页面陷入许多计算的泥潭。但是,使用$'tr:not:last child:not:first child.first.find'输入可能有效。我要试一试。