我正在使用 html 网格。我想获取具有名为 selected 的类的列的索引值。为了更好地理解它,我将给出 html 网格格式
<table style="width:600px;height:200px" id="gdTable" border="1">
<tr>
<td>
<span id="lblFinance">Finance</span>
</td>
<td>
<span id="lblRow1">r1c1</span>
</td>
</tr>
<tr>
<td>
<span id="Label1">Finance1</span>
</td>
<td **class="selected"**>
<span id="Label2">r2c1</span>
</td>
</tr>
<tr>
<td **class="selected"**>
<span id="Label7">Finance2</span>
</td>
<td>
<span id="Label8">r3c1</span>
</td>
</tr>
</table>
我想要的结果是2(第二行列的索引)+1(第三行列的索引)=3
下面给出了我尝试过的jquery。我尝试提醒列索引,但没有得到所需的结果。
function getCellValue() {
$("#gdTable tr").each(function () {
if($(this).children().hasClass("selected")){
var selCOL = $(this).children().hasClass("selected");
alert($(this).index(selCOL));
}
})
}
最佳答案
尝试:
getCellValue();
function getCellValue() {
$("#gdTable tr td.selected").each(function () {
alert($(this).index());
});
}
关于jquery - 获取gridview的列索引值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342976/