yaasshole 2014-04-25
代码如下:
jQuery.fn.extend( { myOwnMember: 3, getMyOwnMember: function () { return this.myOwnMember; }, setMyOwnMember: function (v) { this.myOwnMember = v; return this.myOwnMember; } } ); $("body").myOwnMember; //3 $("body").getMyOwnMember(); //3 $("body").setMyOwnMember(4); //4 $("body").getMyOwnMember(); //3
代码如下:
jQuery.fn.extend( { myOwnMember: 3, getMyOwnMember: function () { return this.myOwnMember; }, setMyOwnMember: function (v) { this.myOwnMember = v; return this.myOwnMember; } } ); var body = $("body"); body.myOwnMember; //3 body.getMyOwnMember(); //3 body.setMyOwnMember(4); //4 body.getMyOwnMember(); //4
代码如下:
jQuery.fn.extend( { getMyOwnMember: function () { return this[0].myOwnMember; }, setMyOwnMember: function (v) { this[0].myOwnMember = v; return this[0].myOwnMember; } } ); $("body").getMyOwnMember(); //undefined $("body").setMyOwnMember(4); //4 $("body").getMyOwnMember(); //4