我有一个包含4个cols的表:
<table id="myTable">
<th>
<td> A </td>
<td> B </td>
<td> C </td>
<td> D </td>
</th>
<tr>
<td>
<span>A-1</span> <span>A-3</span> <span>A-5</span>
</td>
<td>
<span>B-2</span> <span>B-3</span>
</td>
<td>
<span>C-3</span> <span>C-4</span> <span>C-7</span>
</td>
<td>
<span>D-1</span>
</td>
</tr>
</table>我有一个包含A、B、C和D的下拉列表,其中包含一个更改处理程序(A=1、B=2等):
@Html.DropDownListFor(model => model.TypeID, new SelectList(Model.Types, "Key", "Value", Model.TypeID))
$('#myTable').change(function () {
var type = $(this).val();
if (type == 1) {
var tr = $('#current tr')[0];
var td = tr.cells[0].innerHTML;
var last = $(td).find(':last-child');
/// how do I get the contents of the last span???
} else if ( type == 2 ) {
...
}
});最后,一个文本框:
@Html.TextBoxFor(model => model.next)当用户点击下拉列表中的一个选项时,我希望根据最后一个跨度中的内容在相应的表格单元格中放入适当的“下一个”值。我似乎想不出如何得到最后一个,并提取出值。
发布于 2012-05-03 02:08:31
$('#myTable').change(function () {
var type = +$(this).val();
if (type === 1) {
var tr = $('#current tr');
var td = tr.find('td:eq(0)');
var last = td.find('span:last');
var contents = last.html();
} else if ( type == 2 ) {
...
}
});https://stackoverflow.com/questions/10419228
复制相似问题