【发布时间】:2014-10-01 05:44:27
【问题描述】:
我定义了以下数据表。
问题 - 绘制数据表后,当我从滑块 jquery 输入中检索值时,我收到跨度和整个文本而不是值。我如何只检索滑块输入的值?
<table class="zebra" cellpadding ="0" cellspacing="0" border="0" id="subscriptionsTable" width="100%">
<thead>
<tr>
<th>
User
</th>
<th>
Name Full
</th>
<th>
Sub Frequency
</th>
<th>
Price
</th>
<th>
Rep
</th>
<th>
Sales
</th>
<th>
Points
</th>
<th>
Save
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
以下是屏幕上的数值,
<td class="sorting_1">60728</td>
<td>Les</td>
<td>Y</td>
<td>799</td>
<td></td>
<td></td>
<td>
<span class="ui-spinner ui-widget ui-widget-content ui-corner-all">
<input id="pointSlider" class="ui-spinner-input" type="number" step="1" min="0" aria-valuemin="0" autocomplete="off" role="spinbutton" style="border-width: 1px; border-color: rgb(206, 206, 206);" aria-valuenow="4">
<a class="ui-spinner-button ui-spinner-up ui-corner-tr ui-button ui-widget ui-state-default ui-button-text-only" tabindex="-1" role="button" aria-disabled="false">
<a class="ui-spinner-button ui-spinner-down ui-corner-br ui-button ui-widget ui-state-default ui-button-text-only" tabindex="-1" role="button" aria-disabled="false">
</span>
</td>
td>
<img class="save" width="20px" title="Save this record" src="https://localhost:8443/project/images/Green_Check.png">
</td>
当我选择任何行时,我可以使用以下 jQuery 选择来捕获行元素。
$(this).closest('tr').find('td').eq(0).html();
如何选择第 6 个元素?我有一个 ID=pointSlider 的滑块 jquery,但找不到该值。
感谢帮助,jQuery 的新手。
【问题讨论】:
-
您想要当前选定行中的第 6 行或第 6 列?
-
@JawwadAlam 当前选择的第 6 列值。
-
创建fiddle 以清楚地解释您的问题。
-
如果您在
$(this).closest('tr').find('td').eq(0).html();上方的代码为您提供了当前选定行的第一个单元格的内容,您可以对其进行修改以获得第6 个单元格的内容,如$(this).closest('tr').find('td:nth-child(6)').html(); -
@JawwadAlam 这行得通 - $(this).closest('tr').find('#pointSlider').val();测试够了,感谢您的帮助。
标签: javascript jquery datatable cell html-table