Home >php教程 >php手册 >ctrl,shift 多选表格行

ctrl,shift 多选表格行

WBOY
WBOYOriginal
2016-06-07 11:41:241267browse

实现类似资源管理器一样的选择方案
按住ctrl加选,按住shift连选,
active是选中后的CSS效果,自行设计或更改
var lastChecked;<br>     $('#example tbody').on("click","tr", function(event) {<br>                  <br>         if(!lastChecked) {<br>             lastChecked = this;<br>         }<br>          <br>         if(event.shiftKey) {<br>             var start = $('#example tbody tr').index(this);<br>             var end = $('#example tbody tr').index(lastChecked);<br>      <br>             for(i=Math.min(start,end);i                 if (!$('#example tbody tr').eq(i).hasClass('active')){<br>                     $('#example tbody tr').eq(i).addClass("active");<br>                 }<br>             }<br>             <br>             //清楚浏览器光标选择<br>             if (window.getSelection) {<br>                 if (window.getSelection().empty) {  // Chrome<br>                     window.getSelection().empty();<br>                 } else if (window.getSelection().removeAllRanges) {  // Firefox<br>                     window.getSelection().removeAllRanges();<br>                 }<br>             } else if (document.selection) {  // IE<br>                 document.selection.empty();<br>             }<br>         } else if ((event.metaKey || event.ctrlKey)){<br>             $(this).toggleClass('active');<br>         } else {<br>             $('#example tbody tr').removeClass('active');<br>             $(this).toggleClass('active');  <br>         }<br>          <br>         lastChecked = this;<br>     });

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn