Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78420d4

Browse files
authored
Core: Implement .even() & .odd() to replace POS :even & :odd
`:even` & `:odd` are deprecated since jQuery 3.4.0 & will be removed in 4.0.0.The new `even()` & `odd()` methods will make the migration easier.Closesgh-4485
1 parentf810080 commit78420d4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

‎src/core.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ jQuery.fn = jQuery.prototype = {
100100
returnthis.eq(-1);
101101
},
102102

103+
even:function(){
104+
returnthis.pushStack(jQuery.grep(this,function(_elem,i){
105+
return(i+1)%2;
106+
}));
107+
},
108+
109+
odd:function(){
110+
returnthis.pushStack(jQuery.grep(this,function(_elem,i){
111+
returni%2;
112+
}));
113+
},
114+
103115
eq:function(i){
104116
varlen=this.length,
105117
j=+i+(i<0 ?len :0);

‎test/unit/core.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,18 @@ QUnit.test( "first()/last()", function( assert ) {
648648
assert.deepEqual($none.last().get(),[],"last() none");
649649
});
650650

651+
QUnit.test("even()/odd()",function(assert){
652+
assert.expect(4);
653+
654+
var$links=jQuery("#ap a"),$none=jQuery("asdf");
655+
656+
assert.deepEqual($links.even().get(),q("google","anchor1"),"even()");
657+
assert.deepEqual($links.odd().get(),q("groups","mark"),"odd()");
658+
659+
assert.deepEqual($none.even().get(),[],"even() none");
660+
assert.deepEqual($none.odd().get(),[],"odd() none");
661+
});
662+
651663
QUnit.test("map()",function(assert){
652664
assert.expect(2);
653665

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp