Archive for the ‘未分类’ Category.

最简单的JS自动完成(autocomplete)教程

最方便的自动完成制作方法
方便新手学习

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Autocomplete Sample</title>
</head>
<style>
#result{
	background-color:#0CC;
	width:100px;
}
	#result ul{
		padding:0px;
		margin:0px;
	}
</style>
<body>
<input type="text" id="filter" />
<div id='result'></div>
</body>
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script>
//初始化
var js_content=["anhui","beijing","fujian","gansu","guangdong","guangxi","guizhou","hainan","hebei","henan","heilongjia","hubei","hunan","jilin","jiangsu","jiangxi","liaolin","neimengu","ningxia","qinghai","shandong","shanxi","shanghai","sichuan","tianjing","xizang","xinjiang","yunnan","zhejiang","chongqing"];
 
$("#filter").keyup(function(){ //按键
	var filter; //过滤词
	var showResult=[]; //结果数组
	filter=$(this).val(); //根据文本框的值获得过滤词
	$("#result").html(""); //清空结果列表
	$.each(js_content,function(){ //遍历数组,
		if(this.substring(0,filter.length)==filter){//截取数组里的label的指定长度(长度为过滤词的长度)
			showResult.push(this);//如果结果一致,则讲此数组放到showResult
		}
	});
	for(var i=0;i<showResult.length;i++){ //遍历结果数组,放在结果列表
		$("#result").html($("#result").html()+"<ul>"+showResult[i]+"</ul>");
	}
})
</script>
</html>

希望能给大家抛砖引玉~

用setTimeout()代替setInvertal()

新版的小悟空增加了游戏倍速功能,于是问题就出现了——已经定义了setInvertal的函数,不会因为游戏速度的改变而发生改变,思考了一下,还是决定使用setTimeout来替代。

具体实现:
更改前

1
2
3
4
this.t=setInterval(function(){
	_this.stepMove(_this.angle);
}
},500*WSUI.Classes.Global["spd"]);

更改后

1
2
3
4
5
6
7
this.tF=function(){
	_this.t=setTimeout(function(){
		_this.tF();
		_this.stepMove(_this.angle);
	},500*WSUI.Classes.Global["spd"]);
}
this.tF();

Hello world!

本站正式使用Wordpress博客系统,目前处于调试阶段~

原网站点此链接访问