mootools完成特效_使用MooTools,jQuery和Dojo II完成常见任务

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框架-您会为此更好的!

翻译自: https://davidwalsh.name/jquery-mootools-dojo

mootools完成特效

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值