神奇网站Javascript初始化代码块v1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了神奇网站Javascript初始化代码块v1相关的知识,希望对你有一定的参考价值。
Link body class names to trigger javascript. It requires jQuery.
$(function(){ //jquery references the body for grabbing class info and for general awesomness var body = $('body'); jQuery.fx.interval = 5; //apply all methods as root level functions var root = this; //counter var i; // the goods are in here. var pageScripts = { //init is called automatically //use to set up global stuff init:function(){ } }; //determine if any of the pageScripts match the class of the body and call it/them //keep track of how many properties have been executed var numRan = 0; //split up the classes used in the body //array of classes used in the body's class attribute var bodyClasses = body.attr("class").split(" "); //call init pageScripts.init(); //loop through and execute all for(i in bodyClasses){ if(pageScripts[ i ]){ numRan++; pageScripts[ i ].apply(root, []); } } log(numRan + " methods have been executed"); });
以上是关于神奇网站Javascript初始化代码块v1的主要内容,如果未能解决你的问题,请参考以下文章