JavaScript authoritative Guide to learning notes

Source: Internet
Author: User
Tags tagname

Find multiple elements by ID function getelements (/*ids...*/) {var elements = {};for (var i=0; i<arguments.length; i++) {var id = Arguments[i];var ELT =document.getelementbyid ("id"); if (ELT = = null) throw new Error ("No element with ID:" +id); elements[i ] = ELT;} return elements;} A parameter that returns the element's Textcontent or innertext//two parameters, sets the element's textcontent or innertextfunction textcontent with the value parameter's values (element, value) {var content = element.textcontent;if (value = = undefined) {if (content!==undefined) return content;else return element.in Nertext;} Else{if (content!== undefined) element.textcontent = Value;else Element.innertext = value;}} function textcontent () {var child, type, s= ""; for (child=e.firstchild; child!==null; child.nextsibling) {type = Child.nodetype;if (type = = 3| | type = = 4) {s + = Child.nodevalue;} else if (type = = 1) {s + = textcontent (child);}} return s;} function InsertAt (parent, child, N) {if (N < 0 | | n > parent.childNodes.length) throw new Error (' Invalid index '); else if (n ==parent.childnodes.length) Parent.appendchild (Child); Else Parent.insertbefore (Child, Parent.childnodes[n]);} Sorts the first <tbody> row according to the value of the nth cell in each row of the specified table//If there is a comparator function then uses it, otherwise the function sortrows is compared in alphabetical order (table, N, Comparator) {var tbody = Table.tbodies[0];var rows = Tbody.getelementsbytagname ("tr"); rows = Array.prototype.slice.call (rows, 0); Rows.sort (function (Row1, row2) {var cell1 = Row1.getelementsbytagname ("TD") [N];var cell2 = Row2.getelementsbytagname ("TD") [N];var val1 = Cell1.textcontent | | Cell1.innertext;var val2 = Cell2.textcontent | | Cell2.innertext;if (Comparator) Comparator (Val1, val2), if (Val1 < Val2) Return-1;else if (Val1 > Val2) return 1;else R Eturn 0;}); for (var i=0; i<rows.length; i++) Tbody.appendchild (Rows[i]);} Find tables <th> elements so that they can be clicked to click the caption to sort rows by that column Funciton makesortable (table) {var headers = document.getelementsbytagname ("th "); for (var i = 0; I 

  

JavaScript authoritative Guide to learning notes

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.