87,992
社区成员
发帖
与我相关
我的任务
分享$es = $('div');
$es.each(function(i,n){
// 无论你between怎么实现,jquery就是这样调用between的
between(n, i, ['', ''], $es);
});
<!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=gbk" />
<!-- 引入jQuery -->
<script src="jq.js" type="text/javascript">
</script>
<script type="text/javascript">
;
(function($){
$.extend($.expr[":"], {
between: function(a, i, m){
$("#cc").html(m[3]);
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>
<div id="cc"></div>
</body>
</html>