(function($) {
$.extend($.expr[':'], {
group: function(element, index, matches, set) {
var num = parseInt(matches[3], 10);
if (isNaN(num)) {
return false;
}
console.log(index);
console.log(num * 2);
console.log(index % (num * 2) );
return index % (num * 2) < num;
}
});
})(jQuery);
在《jQuery基础教程(第四版)》9.2.1有这么一个自定义选择器,但是我发现这个选择器不起作用,三个 console.log()
是我自己加的,console.log(index)
结果永远是0
,按理说index
不应该是遍历调用者的每个元素吗?已下载了书本提供的官方源代码来测试,排除个人手打出现错误
另外我自己也按照原书的意思调通了一个,js部分代码:
在线Demo:
http://runjs.cn/detail/qrtxmvga