本段代码没有采用jquery传统的写法,因为那样写大括号包小括号,小括号又包大括号实在眼花,所以我把所有函数都分开写了。
本段代码json数据(data表示的数据)是从服务端servlet中取得,如果要在客户端独立运行该段代码,请用自的json数据代替data并在按钮的onclick事件中直接调用myshowJson函数
-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
<title>Insert title here</title>
-
<script type="text/javascript" src=""></script>
-
<script type="text/javascript" >
-
-
function myshowJson(data,status){
-
strHtml="
";
-
strHtml=strHtml+mydg(data,strHtml);
-
strHtml=strHtml+"
";
-
alert(strHtml);
-
$("#myjsonData").html(strHtml);
-
}
-
-
function mydg (data,strHtmlkk){
-
var strHtml=strHtmlkk;
-
-
for(cc in data){
-
if(typeof(data[cc])=='object'){
-
strHtml=strHtml+"
";
-
strHtml=strHtml+"
"+cc+" | ";
-
strHtml=strHtml+"
"+data[cc]+" | ";
-
strHtml=strHtml+"
";
-
strHtml=arguments.callee(data[cc],strHtml);
-
}else{
-
strHtml=strHtml+"
";
-
strHtml=strHtml+"
"+cc+" | ";
-
strHtml=strHtml+"
"+data[cc]+" | ";
-
strHtml=strHtml+"
";
-
}
-
}
-
return strHtml;
-
}
-
-
function mygetJson (){
-
-
$.post("./servlet/TestTemp",{userName:"cccc",password:"ppppp"},function(data,status){myshowJson(data,status);},"json");
-
-
};
-
function myregisterCmd(){
-
$("#cmdLogin").click( mygetJson);
-
alert("registerCmd");
-
};
-
-
$(document).ready(myregisterCmd);
-
-
</script>
-
</head>
-
<body>
-
-
<input type="button" id="cmdLogin" value="testestestest">
-
<div id="msg"></div>
-
<div id="myjsonData"></div>
-
-
</body>
-
</html>
阅读(11352) | 评论(0) | 转发(1) |