练习题10_商品卡片.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. body {
  9. background-color: #f5f5f5;
  10. }
  11. .card-content {
  12. width: 250px;
  13. /* border:1px solid black; */
  14. float: left;
  15. padding: 20px;
  16. background-color: #fff;
  17. /* 阴影 第一个值横向偏移 第二个值纵向偏移 第三个值扩散值 第四个值阴影颜色 */
  18. box-shadow: 0 0 5px #666;
  19. margin:10px;
  20. }
  21. .card-img {
  22. text-align: center;
  23. }
  24. .card-img img {
  25. width: 200px;
  26. }
  27. .card-info h3,.card-info p{
  28. text-wrap: nowrap;
  29. overflow: hidden;
  30. text-overflow: ellipsis;
  31. }
  32. .clearfix::after{
  33. content: "";
  34. display: block;
  35. clear: both;
  36. }
  37. .title-bar{
  38. float: left;
  39. width: 100%;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div class="box clearfix">
  45. </div>
  46. <script src="./ajax.js"></script>
  47. <script>
  48. let oBox = document.getElementsByClassName("box")[0];
  49. ajaxFun("GET", "http://shop-api.edu.koobietech.com/prod/tagProdList", function (res) {
  50. let dataList = res.data;
  51. let htmlStr = "";
  52. for(let j=0;j<dataList.length;j++){
  53. htmlStr += `<div class="title-bar">${dataList[j].title}</div>`
  54. for(let i=0;i<dataList[j].productDtoList.length;i++){
  55. let {pic,prodName,brief,price} = dataList[j].productDtoList[i];
  56. htmlStr += `
  57. <div class="card-content">
  58. <div class="card-img">
  59. <img src="${pic}" alt="图片">
  60. </div>
  61. <div class="card-info">
  62. <h3>${prodName}</h3>
  63. <p>${brief}</p>
  64. <p>¥${price}</p>
  65. </div>
  66. </div>
  67. `
  68. }
  69. }
  70. oBox.innerHTML = htmlStr;
  71. })
  72. </script>
  73. </body>
  74. </html>