单击复选框获取表格行id值
Get the table row id value in Fexigrid on checkbox click?
我正在FlexiGrid上工作,并且很少有脚本问题。我已经成功地创建了一个FlexiGrid并添加了复选框。在复选框上单击,我要选择所需的行。当单击任何一行时,它在<tr id="row101" class="trSelected">
中设置class='trSelected'。我已经尝试了一些脚本设置它复选框单击,但不工作。请让我知道如何解决这个问题。
<script type="text/javascript">
function checkedCall() {
if( $('#checkNote').is(':checked')){
//$("#tblflex > tr:first").addClass("trSelected");
//$(this).parents('tr:first').addClass('trSelected');
alert('Selected' + $(this).parents('tr:first').attr('id')); //unable to find the ID
}else{
alert('NOTSelected');
//$("#tblflex > tr:first").removeClass("trSelected");
//$(this).parents('tr:first').removeClass('trSelected');
}
}
HTML代码:<table id="tblflex" class="flexCLS" style="display: table;" border="0">
<tbody>
<tr id="row101">
<td align="left">
<div style="text-align: left; width: 40px;">
<input type="checkbox" id="checkNote" onclick="checkedCall();">
</div>
</td>
</tr>
<tr id="row187">
<td align="left">
<div style="text-align: left; width: 40px;">
<input type="checkbox" id="checkNote" onclick="checkedCall();">
</div>
</td>
</tr>
谢谢!
问题是你所有的复选框都有相同的ID "checkNote"
这是一个建议的解决方案
HTML<table id="tblflex" class="flexCLS" style="display: table;" border="0">
<tbody>
<tr id="row101">
<td align="left">
<div style="text-align: left; width: 40px;">
<input type="checkbox" id="checkNote101" onclick="checkedCall(this);">
</div>
</td>
</tr>
<tr id="row187">
<td align="left">
<div style="text-align: left; width: 40px;">
<input type="checkbox" id="checkNote187" onclick="checkedCall(this);">
</div>
</td>
</tr>
和JS代码
<script type="text/javascript">
function checkedCall(this) {
if( $(this).is(':checked')){
//$("#tblflex > tr:first").addClass("trSelected");
//$(this).parents('tr:first').addClass('trSelected');
alert('Selected' + $(this).parents('tr:first').attr('id')); //unable to find the ID
}else{
alert('NOTSelected');
//$("#tblflex > tr:first").removeClass("trSelected");
//$(this).parents('tr:first').removeClass('trSelected');
}
}
相关文章:
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- difference between '$(<%= DDL.ID %>) & $('
- 使用Javascript获取所选选项ID
- 根据id将json数组组合为一个json数组
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 我应该使用Ng提交还是点击表格
- CSS表格:从列平移到整个表格宽度
- 对id以某个字符串开头的元素进行计数
- 将HTML表格导出到excel时,无法将数据加载到excel文件中
- Form获胜'没有ID主联系表格无法验证
- 点击链接提交表格并发送到多个电子邮件 ID
- Yii2:Jquery 选择表格单元格的 id 不起作用
- 将单个 id 标签添加到表格单元格中,每个循环都有 Rails
- 获取表格单元格的 ID
- 从我的表格中获取最近的id文本
- 单击复选框获取表格行id值
- 如何获得第一个的id
& lt; tbody>在HTML表格中使用jQuery - 如何在Casperjs中通过输入id填写表格
- 为什么鼠标单击表格行时无法获取行id
- 表格ID &jQuery中的名称