尝试创建一种方法来计算开始和结束元素之间匹配元素的数量。没有什么太狂野了。原来这两个console.log在我中间识别next_item
并end_elem
在无限循环中使我的浏览器崩溃。理想情况下,我试图在 while 循环调用中使用它,这样我就可以防止它通过end_elem
do 捕获它next_item.index() < end_elem.index()
,但这显然每次都会破坏我的浏览器。我不知道为什么。
find_the_count_of_elements_between_two_elements: function(class_to_count, start_elem, end_elem) {
var number_of_times = 0;
var start = 0;
var end = 1;
next_item = start_elem.nextAll().slice(start, end);
while ( start < 6 ) {
// console.log(next_item.index() < end_elem.index() );
console.log("next_item : " + next_item.index() );
console.log("end_elem : " + end_elem.index());
if ( next_item.hasClass(class_to_count) ) {
number_of_times++;
};
start++;
end++;
next_item = start_elem.nextAll().slice(start, end);
console.log(next_item);
};
return number_of_times;
},