Js function-Press Ctrl to select multiple table rows

Source: Internet
Author: User
Tip: you can modify some code before running

Js function-Press Ctrl to select multiple table rows<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>New Document</title><meta name="title" content="" /><meta name="author" content="0xs.cn" /><meta name="subject" content="" /><meta name="language" content="zh-cn" /><meta name="keywords" content="" /><style type="text/css" >/* Default css rule */body {font: 12px "Verdana, ";}# myTable td {-moz-user-select: none;-webkit-user-select: none;} tr. select {background: # fcc ;}</style><script type="text/javascript" >// Shortcutfunction $ (s) {return typeof s = 'object '? S: document. getElementById (s);} // check start & end posfunction checkPos (el) {var oTable = $ ('mytable'); var startPos = oTable. startPos; if (startPos! = Null) {var endPos = el. rowIndex; if (endPos> startPos) {endPos ++;} else {endPos --;} loopRows (oTable, function (cur) {cur. className = ''; cur. childNodes [0]. childNodes [0]. checked = false ;}); // clearloopRows (oTable, function (cur) {cur. className = 'select'; cur. childNodes [0]. childNodes [0]. checked = true;}, startPos, endPos); oTable. startPos = null; return;} oTable. startPos = el. rowIndex; el. className = 'sele Ct ';} // check and select rowsfunction chkSelect (e) {var e = (e | event); var el = this; if (e. shiftKey) {checkPos (el);} if (e. ctrlKey) {el. className = (el. className = 'select '? '': 'Select'); el. childNodes [0]. childNodes [0]. checked = (el. className = 'select') ;}// get rows & do callbackfunction loopRows (oTable, callBack, start, end) {if (! OTable) {return;} callBack = callBack | function () {}; var trs = oTable. rows; var I = start | 0, l = end | trs. length; var flag = I <l; while (flag? I <l: I> l) {var cur = trs [I]; try {callBack (cur, I);} catch (e) {if (e = 'break') {break;} flag? I ++: I --;} // initfunction init () {var oTable = $ ('mytable'); loopRows (oTable, function (cur) {cur. onclick = chkSelect;}); oTable. startPos = null;} window. onload = init;</script></head><body><table cellpadding="0" cellspacing="0" border="1" onselectstart="return false;" width="100%" id="myTable"><script type="text/javascript">For (var I = 0; I <100; I ++) {document. write ('<tr><td><input type="checkbox" /></td><td>'+ I +'</td></tr>');}</script></table></body></html>
Tip: you can modify some code before running

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.