<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="jQuery中的lt和gt方法之不支持该属性的解决方法" id="card1">
<p> 游客</p><p>
标题:jQuery中的lt和gt方法之不支持该属性的解决方法<br/>
正文:<br/>
 在《Learning jQuery》-Better Interaction Design and Web Development with Simple JavaScript Techniques一书中，作者Jonathan Chaffer 和Karl Swedberg 提供的代码中部分函数在新版的jQuery中已经去掉，所以书中提供的分页示例代码无法使用，在国外网站找到解决办法。原书中分页示例代码，用来显示第一页的10行数据：$(document).ready(function() {$('table.paginated').each(function() {var currentPage = 0;var numPerPage = 10;var $table = $(this);$table.find('tbody tr').show().lt(currentPage * numPerPage).hide().end().gt((currentPage + 1) * numPerPage - 1).hide().end();});}); 需要将原代码做如下替换，就可以正常进行分页了：移除.lt(currentPage * numPerPage) 用.slice(0, currentPage * numPerPage)替代...移除.gt((currentPage + 1) * numPerPage - 1)   用.slice((currentPage + 1) * numPerPage - 1)代替另外可以把分页处理修改为：$table.find('tbody tr').hide()        .slice(currentPage * numPerPage, (currentPage + 1) * numPerPage - 1)          .show();也可达到同样之效果。这个代码我在使用中，发现要将numPerPage-1改为numPerPage。各位在测试中看看是否正确。关于slice函数在jQuery中的定义与JavaScript中的定义一致：.slice()用来从匹配的jQuery对象中分离<br/><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=388&amp;Page=1">[&lt;&lt;]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=388&amp;Page=1">[[1]]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=388&amp;Page=2">[2]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=388&amp;Page=3">[3]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=388&amp;Page=5">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=388">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=388">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://www.zhongguosou.com/blog/wap.asp">首页</a>
</p>
</card>
</wml>