我有一张带有colspan rowspan的表格,例如。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<table border=1 id="mytable" >
<tr><td>A1</td> <td> A2 </td> <td> A3 </td><td>A4</td><td>A5</td> <td>A6</td> <td>A7</td> <td>A8</td> </tr>
<tr><td>B1</td> <td colspan=3 >B2-B4</td> <td>B5</td> <td>B6</td> <td>B7</td> <td>B8</td> </tr>
<tr><td>C1</td> <td> C2 </td> <td colspan=3> C3 -C5</td> <td>C6</td> <td>C7</td> <td>C8</td></tr>
<tr><td>D1</td> <td colspan=2 rowspan=2> D2- E3 </td><td>D4</td> <td>D5</td> <td>D6</td> <td>D7</td> <td>D8</td></tr>
<tr><td>E1</td> <td>E4</td> <td>E5</td> <td>E6</td> <td>E7</td> <td>E8</td></tr>
<tr><td>F1</td> <td> F2 </td> <td> F3 </td><td>F4</td><td>F5</td> <td>F6</td> <td>F7</td> <td>F8</td> </tr>
</table>
&#13;
答案 0 :(得分:0)
试试这个Fiddle
JS代码:
var valueStr = 'C2';
var tdObj = $("td:contains('"+valueStr+"')");
var trObj = tdObj.closest('tr');
var tdIndex = trObj.find(tdObj).index();
var reqTD = trObj.next().find('td:eq('+tdIndex+')');
alert(reqTD.html());
答案 1 :(得分:0)
<强> JS Fiddle 强> 这就是我现在尝试的,而不是你所有的测试用例。还在努力
$("#mytable").on('click', 'td', function () {
var self = $(this);
var dt = self.html();
$("#aData1").html("You clicked @ block = " + dt);
var x = self.index();
var y = self.parent().next().find("td:eq(" + x + ")").html();
$("#aData2").html("Next block is : " + y);
});