标签:web前端 javascript
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>New Web Project</title>
		<script src="ajax.js"></script>
	</head>
	<script>
			window.onload=function()
			{
				var oBtn=document.getElementById('btn');
				var oUl=document.getElementById('ul1');
				oBtn.onclick=function(){
					ajax('index.txt',function(str){
						var aa=eval(str);
						//alert(aa);
						for(var i=0;i<aa.length;i++)
						{
							var oLi=document.createElement('li');
							oLi.innerHTML='用户名: '+'<strong>'+aa[i].name+'</strong>'+"  年龄: "+aa[i].age;
							oUl.appendChild(oLi);
						}
						
					});
				}
					
			};
		</script>
	<body>
		<input id="btn" type="button" value="读取" />
		<ul id="ul1">
			
		</ul>
	</body>
</html>
ajax.js如下
运行结果:
标签:web前端 javascript
原文地址:http://blog.csdn.net/u012193330/article/details/41827335