如何使用value成员属性查找元素

时间:2015-05-05 13:38:22

标签: jquery jquery-ui

我需要在gridview中禁用一行,并使用某些条件禁用复选框: 例如:

if (row["Islicense"].toString() == "false") {
   // disable the row and checkbox 
}

此处身份ID为“valuemember”

以下是供您参考的HTML:

<table class="grid_table">
    <colgroup>
        <col style="width: 35px;">
        <col style="width: 150px;">
        <col>
    </colgroup>
    <tbody>
        <tr valuemember="2" id="row_SelectedSiteId0" class="row_even">
            <td>
                <div class="bally-checkbox">
                    <label>
                        <input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId">
                        <span></span>
                    </label>
                </div>
            </td>
            <td>Employee</td>
            <td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td>
        </tr>
        <tr valuemember="1" id="row_SelectedSiteId1" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Asset</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="3" id="row_SelectedSiteId2" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Drop</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="9" id="row_SelectedSiteId3" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Accounting</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="7" id="row_SelectedSiteId4" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Slips</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="5" id="row_SelectedSiteId5" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Tickets</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr>
    </tbody>
</table>

3 个答案:

答案 0 :(得分:0)

这个怎么样:

 if($('tr[valuemember="0"]').length){}

答案 1 :(得分:0)

$('.grid_table tr').each(function() {
   var attr = $(this).attr('valuemember');
  if (typeof attr !== typeof undefined && attr !== false) {
    // has valuemember attribute
  }
});

答案 2 :(得分:0)

迭代表格行并检测所需的属性,与您的条件进行比较并禁用,或者不是相应的行。

在这种情况下,您将禁用valuemember属性等于yourCriteria

的每一行

的jQuery

$('.grid_table tr').each(function() {
   var that = $(this);
   if (that.attr('valuemember') == 'yourCriteria') {
      that.find('input[type=checkbox]').prop('disabled', true);
      that.addClass('disabledRow');
   }
});

CSS

.disabledRow {
   opacity: 0.3
}

DEMO(禁用具有值成员的行== 1)

$('.grid_table tr').each(function() {
   var that = $(this);
   if (that.attr('valuemember') == '1') {
      that.find('input[type=checkbox]').prop('disabled', true);
      that.addClass('disabledRow');
   }
});
.disabledRow {
   opacity: 0.3
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table class="grid_table">
    <colgroup>
        <col style="width: 35px;">
        <col style="width: 150px;">
        <col>
    </colgroup>
    <tbody>
        <tr valuemember="2" id="row_SelectedSiteId0" class="row_even">
            <td>
                <div class="bally-checkbox">
                    <label>
                        <input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId">
                        <span></span>
                    </label>
                </div>
            </td>
            <td>Employee</td>
            <td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td>
        </tr>
        <tr valuemember="1" id="row_SelectedSiteId1" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Asset</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="3" id="row_SelectedSiteId2" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Drop</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="9" id="row_SelectedSiteId3" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Accounting</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="7" id="row_SelectedSiteId4" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Slips</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="5" id="row_SelectedSiteId5" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Tickets</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr>
    </tbody>
</table>

相关问题