An example of how to sort the hotspot of a JavaScript menu item. list items or menu items are sorted by the number of clicks (or other events). Here is just an example, if you want to see a more complete example, you can develop it on this basis.
DEMO code:
<Div> <ul id = "menu"> <li> <span> First </span> </li> <span> Second </span> </li> <li> <span> Third </span> </li> </ul> <p id = "status"> </p> <script> // This sorting method is a default mode // There are two default initial conditions: // first: the level value is not set. The default value is 0. // Second: The level value has been given, and the list // has been scaled from large to small (from top to bottom) arranged. // Therefore, you can compare it with the above elements. Var sortIt = function _ (elt) {var pes = elt. previuselementsibling; if (pes & elt. level> pes. level) {var ihtml = elt. innerHTML, ilevel = elt. level; elt. innerHTML = pes. innerHTML; elt. level = pes. level; pes. innerHTML = ihtml; pes. level = ilevel; _ (pes) ;}; // RBI: Hitting // here, the level value is the number of clicks (onclick event, // rank is the sorting number (starting from 0) by default ). // The more clicks (the larger the level value), the higher the rank. Function rbiIt (elts) {var I; for (I = 0; I <elts. length; I + = 1) {elts [I]. onclick = function (I) {var level = elts [I]. level | 0, rank = elts [I]. rank | I; return function (e) {this. level = ++ level; this. rank = rank; sortIt (this); document. getElementById ("status "). innerHTML = "(" + this. rank + ":" + this. level + ")" ;};}( I) ;}; // initialization // you can specify the level and rank value var elts = document. getElementById ("menu "). children; // var elts = document. getElementsByTagName ("li"); var k; for (k = 0; k <elts. length; k + = 1) {elts [k]. level = 0; // elts [k]. rank = 0;} rbiIt (elts); // you are welcome to copy bkjia.com, reject malicious collection of liehuo.net </script> </div> <br/> <center> If the page cannot be displayed, press Ctrl + F5 to refresh the page. For more webpage code: <a href =' http://www.bkjia.com/ 'Target = '_ blank'> http://www.bkjia.com/ </A> </center>
Tip: the code can be modified before running!