mootools完成特效
My love of the JavaScript frameworks knows no bounds. Unfortunately too many developers stick to one framework without taking the time to learn the others. The more frameworks you know, the better a programmer you will be and the more money you'll make. Let me show you how to accomplish a few more tasks using three JavaScript frameworks: MooTools, jQuery, and Dojo.
我对JavaScript框架的热爱是无限的。 不幸的是,太多的开发人员坚持使用一个框架却没有花时间学习其他框架。 您知道的框架越多,您将成为一名更好的程序员,您就会赚到更多的钱。 让我向您展示如何使用三个JavaScript框架完成更多任务:MooTools,jQuery和Dojo。
遍历元素集合 (Loop Through an Element Collection)
Moo工具 (MooTools)
$$('div').each(function(div) {
/* do stuff here */
});
jQuery的 (jQuery)
jQuery('div').each(function(){
/* do stuff; "this" is the element */
});
道场 (Dojo)
dojo.query('div').forEach(function(div){
/* do stuff */
});
获取元素属性值 (Get an Element Attribute Value)
Moo工具 (MooTools)
var rel = document.id('myElement').get('rel');
jQuery的 (jQuery)
var rel = jQuery('#myElement').attr('rel');
道场 (Dojo)
//var rel = dojo.query('#myElement').attr('rel')[0];
var rel = dojo.attr('myElement','rel');
创建一个插件/类-模板 (Create a Plugin / Class - Template)
Moo工具 (MooTools)
var myClass = new Class({
initialize: function(options) {
/* do initial processing */
}
});
jQuery的 (jQuery)
jQuery.fn.myClass = function(options) {
return this.each(function() {
/* do initial processing */
});
};
道场 (Dojo)
dojo.provide('mynamespace.PluginName');
dojo.declare('mynamespace.PluginName',null,{
constructor: function(options) {
/* do initial processing */
}
});
设置并获取Cookie键=>值 (Set and Get Cookie Key=>Values)
Moo工具 (MooTools)
/* set */
Cookie.write('key','value',{ duration: 5 }); //5 days
/* get */
var cookieValue = Cookie.read('key');
jQuery的 (jQuery)
/*
requires this plugin: http://plugins.jquery.com/project/cookie
*/
/* set */
jQuery.cookie('key','value', { expires: 5 });
/* get */
var cookieValue = jQuery.cookie('key');
道场 (Dojo)
/* get dojo's cookie class */
dojo.require('dojo.cookie');
/* set */
dojo.cookie('key','value', { expires: 5 }); //5 days
/* get */
var cookieValue = dojo.cookie('key');
通过XHR检索JSON (Retrieve JSON via XHR)
Moo工具 (MooTools)
var jsonRequest = new Request.JSON({
url: 'info.json',
onSuccess: function(json){
/* do something with results */
}
}).get();
jQuery的 (jQuery)
jQuery.getJSON('info.json',function(json) {
/* do something with results */
});
道场 (Dojo)
dojo.xhrGet({
url: 'info.json',
handleAs: 'json',
load: function(json) {
/* do something with results */
}
});
There you are -- more proof that the toolkits are one in the same, all except the syntax. Do yourself a favor and learn more than one JavaScript framework -- you'll be better for it!
在这里,您将获得更多的证据,证明除了语法之外,所有工具包都是相同的。 帮自己一个忙,学习不止一个JavaScript框架-您会为此更好的!
mootools完成特效