实现功能要求:
** 通过点击任意一tr中的a#click得出该tr中指定的td中内容 **
html代码
<table id="history_income_list">
<tr class="active">
<th>句段</th>
<th class="yuanwen">原文栏</th>
<th>状态</th>
<th class="yiwen">译文栏</th>
<th class="yiwen">翻译</th>
</tr>
{% for f,y in wenjian %}
<tr data-uid={{forloop.counter}}>
<td>{{forloop.counter}}</td>
<td id="yuanwen" class="yuanwen" name="yuanwen">{{f.yuanwen}}</td>
<td>√</td>
<td id="yiwen" class="yiwen" style="text-align: left;">
<div class="textarea" id="yiwen_show" contenteditable="true">{{y.yiwen}}</div> </td>
<td>
<a href="javascript:void(0);" id="click">百度翻译</a>
<a href="javascript:void(0);" id="g{{forloop.counter}}">搜狗翻译</a>
</td>
</tr>
{% endfor %}
</table>
JS代码
<script type="text/javascript">
$("a#click").click(function(){
var i= $(this).parent('td').parent('tr').data('uid');
console.log("第"+i+"行")
var query = $("tr:eq("+i+")").children().eq(3).text()
console.log("获取当前点击的tr的第3个td文本:"+query)
var yiwen = $("tr:eq("+i+")").children().eq(6).text()
console.log("获取当前点击的tr的第6个td文本:"+yiwen)
</script>
网友评论