jQuery 选择 table 小部件和一列 table 行

jQuery selectable widget and one columns table rows

我试着让select只能够使用这个table的正确部分;问题是我有一个 rowspan 的左边尺寸,我真的不想 select 那些!有什么建议么?谢谢

jsfiddle: https://jsfiddle.net/johnidevo/xLabgoa3/1/

HTML:

<!DOCTYPE html>

<body>
<table border="1" style="width:100%" class="sel-table">

<thead>
  <tr>
    <th  colspan="2">veve</th>
  </tr>
</thead>

<tbody>
  <tr>
    <th rowspan="2">Merged</th>
    <td>Smith</td>      
  </tr>
  <tr>
    <td>Jackson</td>        
  </tr>

  <tr>
    <th rowspan="2">Doe</th>        
    <td>80</td>
  </tr>
  <tr>
    <td>Doe</td>
  </tr>
<tbody>


</table>
</body>

CSS

.ui-selectable>.ui-selected { background-color: #a6c9e2; }
.ui-selectable>.ui-selecting { background: #FECA40; }
.ui-selectable-helper { position: absolute; z-index: 100; border:1px dotted black; }

JavaScript

$(function() {
    $(".sel-table>tbody").bind("mousedown", function (e) {
        e.metaKey = false;
    }).selectable({
        filter: 'tr'
    });
});

将您的 CSS 和 JS 更新为以下 (jsfiddle):

$(function() {
  $(".sel-table>tbody").bind("mousedown", function(e) {
    e.metaKey = false;
  }).selectable({
    filter: 'td'                  // < === HERE ===
  });
});
.ui-selectable .ui-selected {     // < === HERE ===
  background-color: #a6c9e2;
}

.ui-selectable .ui-selecting {
  background: #FECA40;
}

注:

event.metaKeyread-only property.