标签:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head runat="server"> 4 <title></title> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6 <style> 7 * { margin:0; padding:0;} 8 body { font-size:12px;} 9 #loading{ 10 width:80px; 11 height: 20px; 12 background:#bbb; 13 color:#000; 14 display:none; 15 } 16 img{border:0;height:100px;width:100px;} 17 .comment { margin-top:10px; padding:10px; border:1px solid #ccc;background:#DDD;} 18 .comment h6 { font-weight:700; font-size:14px;} 19 .para { margin-top:5px; text-indent:2em;background:#DDD;} 20 </style> 21 <!-- 引入jQuery --> 22 <script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script> 23 <script> 24 $(function(){ 25 //demo1: 26 $(‘#send1‘).click(function() { 27 $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=car&tagmode=any&format=json&jsoncallback=?", 28 function(data){ 29 $("#resText1").empty(); 30 $.each(data.items, function( i,item ){ 31 $("<img/> ").attr("src", item.media.m ).appendTo("#resText1"); 32 if ( i == 3 ) { 33 return false; 34 } 35 }); 36 } 37 ); 38 }); 39 40 //demo2: 41 $("#send2").click(function(){ 42 $.post("get1.jsp", { 43 username : $("#username").val() , 44 content : $("#content").val() 45 }, function (data, textStatus){ 46 $("#resText2").html(data); // 把返回的数据添加到页面上 47 } 48 ); 49 }) 50 51 //共用这2个全局的ajax事件 在ajax请求过程中,只要图片还未加载完毕,就会一直显示“加载中……”的提示信息 52 $("#loading").ajaxStart(function(){ 53 $(this).show(); 54 }); 55 $("#loading").ajaxStop(function(){ 56 $(this).hide(); 57 }); 58 59 60 }) 61 </script> 62 </head> 63 <body> 64 <br/> 65 <div id="loading">加载中...</div> 66 67 <br/> 68 Demo1: 69 <br/> 70 <input type="button" id="send1" value="加载"/> 71 <div id="resText1" ></div> 72 73 74 <br/> 75 Demo2: 76 <br/> 77 <form id="form1"> 78 <p>评论:</p> 79 <p>姓名: <input type="text" name="username" id="username" /></p> 80 <p>内容: <textarea name="content" id="content" ></textarea></p> 81 <p><input type="button" id="send2" value="提交"/></p> 82 </form> 83 <div class=‘comment‘>已有评论:</div> 84 <div id="resText2" > 85 </div> 86 87 88 </body> 89 </html>
标签:
原文地址:http://www.cnblogs.com/a757956132/p/5000218.html