JS to table and UL Li implementation of the front page introduction

Source: Internet
Author: User
Tags prev

  This article mainly introduces the JS to table and the UL Li realizes the front page paging, needs the friend to be possible to refer to under

The   code is as follows: (function ($) { $.fn.tablepage = function (Oobj, dcountofpage, fresh_id) {  var dpageindex = 1; &nb Sp var dnowindex = 1;   var spagestr = "";   var dCount = 0;   var Osource = $ (this);   var snoselcolor = "#CCCCCC";   var sselcolor = "Black";   var sfontcolor = "White";   var nowindex = 1;     change_page_content ();     Function change_page_content () {   //get the data number    dcount = Osource.children (). Children () . length;    //Shows page    spagestr = "<div class= ' ref ' ><a href= ' javascript:void (0) '  id= ' Fresh_ '" & nbsp    + fresh_id      + "' onclick= ' fresh (this.id); ' class= ' sx ' style= ' color: #247AA9; ' ><span> refresh </span></a></div> ";    SPAGESTR + +  <div class= ' MSDN ' ><a href= ' javascript:void (0) ' > Home </a><a href= ' Javascript:void (0) ' > prev </a><a href= ' javascript:void (0) ' > next page/a><a href= ' javascript:void (0) ' > Last </a></div> ';    SPAGESTR + = "<div class= ' txt ' >" + "Total" +math.ceil (dcount/dcountofpage) + "page, current First" + "<strong>" + dnowindex+ "</strong>" + "page" + "</div>";      oobj.html (SPAGESTR);    dpageindex = 1;    //Filter Table content    var Rr=osource.children () Children ("tr");    osource.children (). Children ("tr"). each (function () {   //==2     if (Dpageindex >= ( ((dNowIndex-1) * dcountofpage) + 1)       && dpageindex <= ((Dnowindex * dcountofpage))) {&N Bsp    $ (this). Show ();    } else {     $ (this). Hide ();    }       dpageindex++;    });    //Osource.children (). Children ("tr"). Head must display    if (dcount<=dcountofpage) {    var tt=$ ("#table_page_" +fresh_id). Children ('. MSDN '). Children (). Each (function (i) {      if (i==2| | i==3| | i==0| | I==1) {      $ (this). addclass ("Disabled");      }    });   &NBSP}    else if (Dnowindex==math.ceil (dcount/dcountofpage)) {    var tt=$ ("#table_page_" + fresh_id). Children ('. MSDN '). Children (). Each (function (i) {     if (i==2| | i==3) {      $ (this). addclass ("Disabled");      }    });    }else if (dnowindex==1) {    var tt=$ ("#table_page_" +fresh_id). Children ('. MSDN '). Children (). Each (function (i) {     if (i==0| | I==1) {      $ (this). addclass ("Disabled");      }    });   &NBSP}    //add to the events    oobj.children (). Children (). each (function () {      $ (th IS). Click (function () {         dnowindex = $ (this) [0].innerhtml;        if ( Dnowindex = = ' Home ') {        DNoWindex = 1;         change_page_content ();         Nowindex = Dnowindex;       &NBSP}        if (Dnowindex = ' last ') {        Dnowindex = M Ath.ceil (Dcount/dcountofpage);         change_page_content ();         Nowindex = Dnowindex;       &NBSP}        if (dnowindex = ' next page ') {       -if (nowindex < Math.ceil (dcount/dcountofpage)) {         dnowindex = parseint (nowindex) + 1;   &NB Sp      change_page_content ();          nowindex = Nowindex + 1;        }       &nbsp,        if (dnowindex = ' prev ') {  &NB Sp     if (Nowindex > 1) {         dnowindex = parseint (nowindex)-1;     & nbsp    change_page_coNtent ();          nowindex = nowIndex-1;        }        }      }    });  }  }; }) (JQuery);     Code as follows: <script type= "Text/javascript" > $ (document). Ready (function () { var totalpage=$ ("ul Li") . length;  var total = Math.ceil ($ ("ul Li"). LENGTH/5);  var current = 1;  //var index = 4;  if (totalpage>5) {  $ ("UL Li:gt (4)"). Hide ();   $ ("#btnPrev"). attr ("Class", " Tabs-scroller-left-disabled "). attr (" Disabled "," Disabled "). Click (function () {   debugger;    $ ( "#btnNext"). attr ("Class", "tabs-scroller-right");    $ ("#btnNext"). Removeattr ("Disabled");    current-= 1;    var tt=current;    $ ("ul Li"). Show ();    var indexstart = (current-1);    var indexend = Indexstart + 4;    $ ("Li:lt + Indexstart +"), Li:gt ("+ Indexend +") ", $ (" ul ")). Hide (); &nbsp  if (current = = 1) {    $ (this). attr ("Class", "tabs-scroller-left-disabled");     $ (this). attr ( "Disabled", "disabled");    }  });   $ ("#btnNext"). Click (function () {   debugger;    $ ("#btnPrev"). attr ("Class", " Tabs-scroller-left ");    $ ("#btnPrev"). Removeattr ("Disabled");    current + 1;    $ ("ul Li"). Show ();    var indexstart = (current-1);    var indexend = current + 4  > $ ("ul Li"). Length-1? $ ("ul Li"). Length-1: Current +3;    $ ("Li:lt + Indexstart +"), Li:gt ("+ Indexend +") ", $ (" ul ")). Hide ();    if (current+4 >= totalpage) {    $ (this). attr ("Class", "tabs-scroller-right-disabled");     $ (this). attr ("Disabled", "disabled");    }    });  }else{  Alert (1);   $ ("#btnPrev"). attr ("Class", "tabs-scroller-left-disabled");   $ ("#btnNext") . attr ("Class", "Tabs-scrolleR-right-disabled ");  }}); </script>    

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.