Some methods of JavaScript and jQuery

1, jQuery.each () (Loop through)

jQuery.each () function is used to traverse the array of the specified object and
instance:

//result为遍历对象,m为累加器,obj对应每个m所对应的result值
jQuery.each(result, function(m,obj){
		alert(obj);
		})

2, setInterval () {} (timer function)

setInterval () method in accordance with a specified period (in milliseconds) to the calling function or calculation expression.
setInterval () method will continue to call the function, until the clearInterval () is called, or the window is closed. A setInterval () ID is used as a parameter value returns the clearInterval () method.

Example:

setInterval(function(){
			//执行方法
						},1000);   //每秒调用一次
//常配合ajax使用
setInterval(function(){
						$.ajax({
							url:'/Software-cup001/Current',
							
							//默认值: true,dataType 为 script 和 jsonp 时默认为 false。设置为 false 将不缓存此页面。
							cache:false,
							dataType:"json",
							data:{},
							//仅在服务器数据改变时获取新数据。默认值: false
							ifModified:false,
							success: function(result){
								
								//jQuery.each() 函数用于遍历指定的对象和数组
//								jQuery.each(result, function(a,obj){
//									var x = (new Date()).getTime();
//									alert(result.length);
									
								if(r>result.length){
									t=result.length;
									
								}
								r=result.length;
								for(;t<result.length;t++){	
//									alert(result[0].site);
									if(result[t].site=="校园大门"){
										
										var x = (new Date()).getTime();
										series.addPoint([x,result[t].headnum],true,true);
										activeLastPointToolip(options);
										}													
								}
//								});
							}
						});	
						},1000);

setTimeout () (timer)

setTimeout () method is used in the calculation expression or function call after a specified number of milliseconds.
Example:

setTimeout(function(){ alert("Hello"); }, 3000);
setTimeout("pie()",60000);

Guess you like

Origin blog.csdn.net/erhuobuer/article/details/94598714