Javascript table operations Daquan: Table Sorting/Reverse Order, dynamic addition of columns, batch deletion, deletion of a row, line color, mouse hover switch background color, select all/reselect. (Compatible with IE and Firefox)

Source: Internet
Author: User


Table Format .html

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

Domutil. js

(This JS is made up of class notes, and some code is not used this time)

VaR customfunctions = {// get the set of sub-nodes (General for IE and ff) getchildnodes: function (node) {var arr = []; var nodes = node. childnodes; For (var I in nodes) {If (nodes [I]. nodetype = 1) {// search for the element node arr. push (nodes [I]) ;}} return arr ;}, // get the first element subnode (ie, FF General) getfirstelementchild: function (node) {return node. firstelementchild? Node. firstelementchild: node. firstchild;}, // get the last element sub-node (ie, FF General) getlastelementchild: function (node) {return node. lastelementchild? Node. lastelementchild: node. lastchild;}, // obtain the previous adjacent node (ie, FF General) getpreviussibling: function (node) {// return the node after finding the previous node, if the node is not found, the nulldc {node = node is returned. previussibling;} while (node & node. nodetype! = 1) return node;}, // obtain the next adjacent node (ie, FF General) getnextsibling: function (node) {// return the node after finding the next node, if the node is not found, the nulldc {node = node is returned. nextsibling;} while (node & node. nodetype! = 1) return node;}, // Insert the element to the end of the specified node. insertafter: function (newnode, targetnode) {If (newnode & targetnode) {var parent = targetnode. parentnode; var nextnode = This. getnextsibling (targetnode); If (nextnode & parent) {parent. insertbefore (newnode, nextnode);} else {parent. appendchild (newnode) ;}}};/* clear spaces before and after the string */string. prototype. trim = function () {return this. replace (/^ \ s * | \ s * $/, "") ;};/* search element: $ q ("Div"): bytagname $ q (". L "): byclassname $ q (" # l "): byid $ q (" $ name "): bynameselector: parentelement: parent element */window. $ q = function (selector, parentelement) {If (selector & (typeof selector) = 'string') {selector = selector. trim (); // remove the leading and trailing spaces var parentel = parentelement | document; var nodearr = new array (); var firstchar = selector. substr (); // obtain the first character. // It starts with #, indicating that if (firstchar = '#') {return parentel. getelementbyid (selector. substr (1);} // search for else if (firstchar = '$') {var all = parentel according to the name starting with $. getelementsbytagname ("*"); For (VAR I = 0; I <all. length; I ++) {var name = All [I]. getattribute ("name"); If (name = selector. substr (1) {nodearr. push (ALL [I]) ;}} Delete I; return nodearr ;}// use. start with else if (firstchar = '. ') {var classname = selector. substr (1); If (parentel. getelementsbyclassname) {return parentel. getelementsbyclassname (classname);} else {var childlist = parentel. getelementsbytagname ("*"); For (VAR I = 0; I <childlist. length; I ++) {var nodeclassname = childlist [I]. classname; var classnamearr = nodeclassname. split (''); For (var j = 0; j <classnamearr. length; j ++) {If (classnamearr [J] === classname) {nodearr. push (childlist [I]) ;}} Delete J ;}delete I; return nodearr ;}// otherwise, query else {return parentel Based on the tag name. getelementsbytagname (selector) ;}} else {return document. all | document. getelementsbytagname ("*");}};

Related Article

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.