我需要在html表中的td中点击correspoding复选框的表头找到类。实际上存在两个标题行。请帮我写js代码。
<table runat="server" border="1" width="100%">
<tr ><th colspan="4">Aetna cOmmercial</th></tr>
<tr class="row0">
<th class=colindex0 >Alta</th>
<th class=colindex1>Hplan</th>
<th class=colindex2 >Hosp</th>
<th class=colindex3 >Other</th>
</tr>
<tr class="row1">
<td class="gvclass1">
<asp:CheckBox ID="CheckBox1" runat="server" Checked="true" /></td>
<td class="gvclass1">
<asp:CheckBox ID="CheckBox2" runat="server" /></td>
<td class="gvclass1">
<asp:CheckBox ID="CheckBox3" runat="server" /></td>
<td class="gvclass1">
<asp:CheckBox ID="CheckBox4" runat="server" /></td>
<tr></table>
答案 0 :(得分:0)
为每个复选框分配一个类,然后你可以找到最接近的td索引,然后找到之前的tr并过滤掉该索引对应的那个。
注意:您的html结构无效,因为最后一个tr未正确关闭。
$(document).ready(function () {
$(".chk").click(function () {
//debugger;
var $td = $(this).closest('td');
var $th = $td.closest('tr').prev('tr').find('> th:eq(' + $td.index() + ')');
console.log($th.attr('class'));
});
});
答案 1 :(得分:0)
这里我调整了你的代码,所以当你点击任何一个复选框时,它会显示相应的项目。 (你需要有jQuery)
implicit def genericDecoder[A, R](
implicit
gen: LabelledGeneric.Aux[A, R],
dec: Lazy[JsonDecoder[R]]
): JsonDecoder[A] = createInstance(a => gen.from(dec.value.decode(a)))
我希望我有所帮助!