日期:2014-05-16 浏览次数:20338 次
<!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(document).ready( function() { var total = Math.ceil($("ul li").length / 3); var current = 1; $("ul li:gt(2)").hide(); $("#btnPrev").attr("disabled", "disabled").click( function() { $("#btnNext").removeAttr("disabled"); current -= 1; $("ul li").show(); var indexStart = (current - 1) * 3; var indexEnd = indexStart + 2; $("li:lt(" + indexStart + "), li:gt(" + indexEnd + ")", $("ul")).hide(); if (current == 1) $(this).attr("disabled", "disabled"); }); $("#btnNext").click( function() { $("#btnPrev").removeAttr("disabled"); current += 1; $("ul li").show(); var indexStart = (current - 1) * 3; var indexEnd = current * 3 - 1 > $("ul li").length - 1 ? $("ul li").length - 1 : current * 3 - 1; $("li:lt(" + indexStart + "), li:gt(" + indexEnd +")", $("ul")).hide(); if (current == total) $(this).attr("disabled", "disabled"); }); }); </script> </head> <body> <ul> <li>01</li> <li>02</li> <li>03</li> <li>04</li> <li>05</li> <li>06</li> <li>07</li> </ul> <input type="button" id="btnNext" value="下一页" /><input type="button" id="btnPrev" value="上一页" /> </body> </html>