我正在研究 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');
}
}
关于javascript - 单击复选框时获取 Fexigrid 中的表行 ID 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15398648/