如果我拥有的唯一信息是哪个tr包含带按钮的td,我如何获取dataTable表中按钮的id。有多个td,按钮可能不是第一个。我需要的按钮ID是“.delete_email”,请注意,可能有多个具有相同类名的按钮ID。
我试过了:
var id = $('#view_all_emails1').DataTable().$('tr.selected td:nth-child(5) button[".delete_email"]').attr("id");
但这会导致错误:
未捕获错误:语法错误,无法识别的表达式:tr.selected td:nth-child(5)button [“。delete_email”]
html:
<tr>
<td>Wed 13-07-16</td>
<td><a href="mailto:?????@?????.???.??">????????</a></td>
<td><a href="index.php?a=em&id=5&ebox=1&et=1" onClick="OpenEmail(5); return false;">
<div class="visible-lg hidden-md hidden-sm hidden-xs" style="color:#06F;">The quick brown fox jumps over the lazy dog!</div>
<div class="visible-md hidden-lg hidden-sm hidden-xs" style="color:#06F;">The quick brown fox jumps over the lazy dog!</div>
<div class="visible-sm hidden-lg hidden-md hidden-xs" style="color:#06F;">The quick brown fox jumps over the lazy dog!</div>
<div class="visible-xs hidden-lg hidden-md hidden-sm" style="color:#06F;">The quick brown fox<br />jumps over the lazy<br />dog! </div></a></td>
<td>enquiries</td>
<td><span class="octicon octicon-mail-read" title="Read!"></span></td>
<td>
<input type='hidden' id='this_id' name='this_id' value='5'/><input type='hidden' id='et' name='et' value='1'/><span class="input-group-btn"><button type="button" id="4:5" name="delete_email" class="delete_email btn btn-danger btn-xs" title="Delete this email!"><span class="glyphicon glyphicon-trash"></span></button></span></td>
<td>2.1<small>kb</small></td>
</tr>
答案 0 :(得分:1)
为什么不这样?
&#39; delete_email&#39;作为名称
bro
或
&#39; delete_email&#39;作为班级
var id = $('#view_all_emails1 tr.selected input button[name="delete_email"]').attr('id');
答案 1 :(得分:1)
我不知道您为什么需要通过DataTable API来获取此值。
var id = $('#view_all_emails1 tr.selected .delete_email').attr('id');