mootools
Very rarely does a developer have the ability to work with just one framework. Often a developer needs to float between MooTools and jQuery. As you can imagine, doing so can make a developer loopy due to the syntax difference. One of the small differences that gets used often is jQuery's attr() and css() vs. MooTools' set() and setStyle(). I've implemented css() and attr() into MooTools for jQuery users.
开发人员很少能够只使用一个框架。 开发人员通常需要在MooTools和jQuery之间浮动。 如您所料,由于语法差异,这样做会使开发人员感到困惑。 经常使用的小差异之一是jQuery的attr()和css()与MooTools的set()和setStyle() 。 我已经为jQuery用户在MooTools中实现了css()和attr() 。
MooTools JavaScript代码 (The MooTools JavaScript Code)
/* implement */
Element.implement({
css: function(property,value) {
var type = $type(property);
if(value == undefined && type != 'object') {
return this.getStyle(property);
}
else {
var pvs = property;
if(type != 'object') { pvs = {}; pvs[property] = value; }
return this.setStyles(pvs);
}
},
attr: function(property,value) {
var type = $type(property);
if(value == undefined && type != 'object') {
return this.get(property);
}
else {
var pvs = property;
if(type != 'object') { pvs = {}; pvs[property] = value; }
return this.set(pvs);
}
}
});
/* css testing! */
//will return "200px"
console.log('css(width) = ' + $('subject').css('width'));
//will set width value to "500px"
console.log('css(width,500) = ' + $('subject').css('width',500));
//will set width value to "700px"
console.log('css(width,700) = ' + $('subject').css({width:700}));
/* attr testing! */
//will return "moo"
console.log('attr(rel) = ' + $('subject').attr('rel'));
//will set width value to "500px"
console.log('attr(rel,mootools) = ' + $('subject').attr('rel','mootools') + ' :: ' + $('subject').attr('rel'));
//will set width value to "700px"
console.log('attr(rel,mootools ftw!) = ' + $('subject').attr({rel:'mootools ftw'}) + ' :: ' + $('subject').attr('rel')
I personally don't prefer this syntax in MooTools but hopefully this helps someone!
我个人不希望在MooTools中使用此语法,但希望对您有所帮助!
mootools