我不知道怎么才能找到前一个。使用jQuery类"cmd and path“。
下面是我的html代码:
<tr>
<td>MySQL</td>
<td class="path">/etc/init.d/mysql</td>
<td class="cmd">status</td>
<td><i class="icon-remove"></i> <i class="icon-pencil"></i></td>
</tr>我的jQuery代码如下所示:
$('i.icon-pencil').click(function() {
var text = $(this).prev('.cmd').text();
alert(text);
});发布于 2013-05-13 20:58:22
$('i.icon-pencil').click(function() {
var text = $(this).closest('td').prev('.cmd').text();
alert(text);
});发布于 2013-05-13 21:00:35
$('i.icon-pencil').click(function() {
var tr = $(this).closest('tr'),
txtPath = tr.find('.path').text(),
txtCmd = tr.find('.cmd').text();
});发布于 2013-05-13 20:59:17
您可以使用:
$('i.icon-pencil').click(function() {
var parent = $(this).parent(),
txtCmd = parent.prev('.cmd').text(),
txtPath = parent.prev('.path').text();
});https://stackoverflow.com/questions/16522639
复制相似问题