Select multiple HTML table rows with Ctrl+click and Shift+click

前端 未结 6 1258
再見小時候
再見小時候 2021-01-31 20:20

Demo

I want to select multiple rows using Windows Shift and Ctrl keys, like multiple folder selection in Windows.

From table of selected ro

6条回答
  •  日久生厌
    2021-01-31 21:15

    Here's a jQuery plugin I wrote recently for a project. Thought sharing...

    Works exactly like you're used to, + it's extremely fast cause it operates over an Array without the need to check for attributes, classes etc, and the add/removeClass triggers only on the selected elements:

    // Use like:
    // $("table").selekt();
    //
    // Available options:
    $("table").selekt({
      children: "tr",           // Elements to target (default: "tbody tr")
      className: "selected",    // Desired CSS class  (default: "selected")
      onSelect: function(sel) { // Useful callback
        $("span").text(sel.length + ' in ' + this.id);
      }
    });
    .selected { background: #0bf; }
    table {border: 1px solid #555;display: inline-block; vertical-align: top;}

    Seleceted: 0

    1 SELECT ME
    2 SELECT ME
    3 SELECT ME
    4 SELECT ME
    5 SELECT ME
    6 SELECT ME
    1 SELECT ME
    2 SELECT ME
    3 SELECT ME
    4 SELECT ME

提交回复
热议问题