example12.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <button id="ok">换一组</button>
  9. <div id="container"></div>
  10. <script src="js/jquery.min.js"></script>
  11. <script>
  12. $(function() {
  13. $('#ok').on('click', function() {
  14. $.ajax({
  15. 'url': 'http://api.tianapi.com/meinv/',
  16. 'type': 'get',
  17. 'data': {
  18. 'key': '772a81a51ae5c780251b1f98ea431b84',
  19. 'num': 12
  20. },
  21. 'dataType': 'json',
  22. 'success': function(jsonObj) {
  23. $('#container').empty();
  24. $.each(jsonObj.newslist, function(index, mmObj) {
  25. var img = $('<img>').attr('width', '250')
  26. .attr('src', mmObj.picUrl);
  27. $('#container').append(img);
  28. });
  29. }
  30. });
  31. /*
  32. var url = 'http://api.tianapi.com/meinv/?key=772a81a51ae5c780251b1f98ea431b84&num=10';
  33. $.getJSON(url, function(jsonObj) {
  34. $('#container').empty();
  35. $.each(jsonObj.newslist, function(index, mm) {
  36. $('#container').append(
  37. $('<img>').attr('width', '250').attr('src', mm.picUrl)
  38. );
  39. });
  40. });
  41. */
  42. });
  43. });
  44. </script>
  45. </body>
  46. </html>