Skip to content

Instantly share code, notes, and snippets.

@dallaslu
Created Oct 10, 2015
Embed
What would you like to do?
require.config({
paths: {
"jquery": "../jquery/2.1.1/jquery.min.js"
}
}); // require 框架
(function($){
window.alert = function( msg ){
$('#message').append( msg );
}
Date.prototype.formatBy = function( f ){
// ...
};
// jQuery $(document).ready(fn) 简写
$(function(){
// 匿名函数
var $element; // 缓存 jQuery 查询结果,提升性能
$element = $("#unique .menus:first").find("li:nth-child(3n-1)").filter(":has(a)"); // 选择与过滤
$element.on("click", "a.menu-item", function(){ // 绑定
var $this = $(this);
var orgin = $this.attr("href");
return orgin == 'http://v2ex.com' ? function(){
alert('wow');
return false; // 事件冒泡
}:function(){
alert(orgin);
var startAt = + new Date(); // 类型转换
$.ajax{{ // ajax
url: $this.data('ajax'),
success: function( resp ){
alert((+ new Date() - startAt) + resp);
}
}}
return false;
};
}());
$element.show('slow'); // 动画
});
})(jQuery); // <- 闭包
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment