jQuery中文入门指南,翻译加实例,jQuery的起点教程

2019-06-03 06:29:31王旭

从上一章的tablesorter插件用法我们可以看到,既可以省略所有参数来使用或者通过一个 key/value 对来重新设置每个参数.

作为一个练习,你可以试着将 第四章 的功能重写为一个插件.这个插件的骨架应该是像这样的:

$.fn.rateMe = function(options) {
	var container = this; // instead of selecting a static container with $("#rating"), we now use the jQuery context
	
	var settings = {
		url: "rate.php"
		// put more defaults here
		// remember to put a comma (",") after each pair, but not after the last one!
	};
	
	if(options) { // check if options are present before extending the settings
		$.extend(settings, options);
	}
	
	// ...
	// rest of the code
	// ...
	
	return this; // if possible, return "this" to not break the chain
});

Next steps(下一步)

如果你想做更好的javascript开发,建议你使用一个叫 FireBug的firefox插件. 它提供了断点调试(比alert强多了)、观察DOM变化等很多漂亮的功能

如果你还有未解决的问题,或者新的想法与建议,你可以使用jQuery的邮件列表 jQuery mailing list.

关于这个指南的任何事情,你可以写mail给作者或者发表评论在他的日志:blog.

关于这个指南的翻译任何事情,你可以写mail给我或者发表评论在我的日志:blog.

还有什么...

大大感谢John Resig创造了这么好的library! 感谢jQuery community 为John提供了如此多的咖啡和其他的一切!

© 2006, Jörn Zaefferer - last update: 2006-09-12

中文版翻译:Keel - 最后更新: 2006-12-13