Dav*_*vid 1 javascript jquery web
当有人点击我的表中的"下载"按钮时,我想将该特定行的日期值传递给函数.目前我只能传递第一个表行的日期值.
这是我正在使用的选择器:
$(this).parent().find('#period-start');
Run Code Online (Sandbox Code Playgroud)
总是回归:
[<td id=?"period-start">?5/1/2013?</td>]
Run Code Online (Sandbox Code Playgroud)
我已经尝试了父,子,查找和最近选择器的组合,但是无法偶然发现正确的选择器从当前行中获取日期值.谢谢.
表
<table id="tblStatements" class="table">
<thead>
<tr>
<th>Period Starting</th>
<th>Period Ending</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<tr>
<td id='period-start'>5/1/2013</td>
<td id='period-end'>5/31/2013</td>
<td><button type='submit'>Download</button></td>
</tr>
<tr>
<td id='period-start'>4/1/2013</td>
<td id='period-end'>4/30/2013</td>
<td><button type='submit'>Download</button></td>
</tr>
<tr>
<td id='period-start'>3/1/2013</td>
<td id='period-end'>3/31/2013</td>
<td><button type='submit'>Download</button></td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
ID总是在HTML中是唯一的.所以,你可以试试这个,没有使用ID:
// Get the first td
var periodStart = $(this).closest('tr').children('td:eq(0)').text();
// Get the second td
var periodEnd = $(this).closest('tr').children('td:eq(1)').text();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18714 次 |
| 最近记录: |