前端代码展示
<tr>
<td width="45%">{{ resource.name }}</td>
<td width="20%" >{{ resource.r_start_time }}</td>
<td width="20%">{{ resource.r_end_time }}</td>
<td width="15%">
<a data-toggle="modal" data-target="#editResource" rel="{{ resource.id }}" name="see">修改
</a> <a rel="{{ resource.id }}" name="delete">删除</a>
</td>
</tr>
如上所见,我想实现的是,通过点击点击a标签
实现修改功能,然后通过a标签索引
得到上面每个td的值
jq代码展示
$('.show-resource table tbody tr td a').click(function() {
let id = $(this).attr("rel");
let html = $(this).parent().siblings('td');
console.log(id)
console.log(html[0].outerText)
console.log(html[1].outerText)
console.log(html[2].outerText)
});
$(this)
代表当前的a标签
,通过$(this).parent()
即可获取当前a标签
所在的td
,siblings
可以获取标签的同级标签,通过打印参数html
,可以看到同级标签数