自執行函數

###自執行函數###css

相比函數調用,當頁面加載或者調用父函數時,讓函數自動執行會簡單些,簡單地將你的函數包裝在小括號內,並額外添加一對圓括號,其本質上就是調用了這個函數。html

(function($) {
	$("#questionback").click(function() {
		window.location.href = "questionnaire.html";
	});
	$.sexlifeIntr = function(arg) {
		var showBar = arg.showBar;
		if(showBar == "false") {
			$("#blank").addClass("hide");
			$(".page-header").addClass("hide");
			$(".evaluationIntr").css("margin-top","0px");
		}
		$("#sexlifeBtn").click(function() {
			window.location.href = "sexlife.html";
		});
	}
})(jQuery);

自執行函數例子:ide

(function($str){
	alert($str);
})("我是自執行函數");
(function test(a, b) {
			alert(a + b);
		})(1, 2);
相關文章
相關標籤/搜索