六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 144|回复: 0

jQuery自定义选择器示例

[复制链接]

升级  8.33%

67

主题

67

主题

67

主题

举人

Rank: 3Rank: 3

积分
225
 楼主| 发表于 2013-2-7 21:08:04 | 显示全部楼层 |阅读模式
示例代码:
<!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>        <title>插件4,between</title>        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />        <!--   引入jQuery -->        <script src="../../scripts/jquery-1.3.1.js" type="text/javascript">        </script>        <script type="text/javascript">            ;            (function($){                $.extend($.expr[":"], {                    between: function(a, i, m){                        var tmp = m[3].split(",");                        return tmp[0]-0<i && i<tmp[1]-0;//tmp[0],eg为2,i>2的时候,并且i<5,另外一个边界,条件成立,根据索引值i,保留其所对应的Dom元素.                    }                })            })(jQuery);                        //插件应用            $(function(){                alert("执行前");                $("div:between(2,5)").css("background","white");                alert("执行后");            })        </script>    </head>    <body>        <div style="background:red">            0        </div>        <div style="background:blue">            1        </div>        <div style="background:green">            2        </div>        <div style="background:yellow">            3        </div>        <div style="background:gray">            4        </div>        <div style="background:orange">            5        </div>    </body></html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表