Created
October 10, 2015 08:58
-
-
Save dallaslu/acc8f5b81ee4a7d9878d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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