1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>json</title> <style> ul,p{ margin: 0; padding: 0; } li{ list-style: none; } img{ display: block; border: none; } a{ text-decoration: none; } .jlist{ display: flex; } .jlist>li{ width: 33.3%; padding: 5px; box-sizing: border-box; font-size: 14px; line-height: 22px; } .jlist>li img{ width: 100%; } .name{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #999; } .time{ color: #ccc; } </style> </head> <body> <ul class="jlist"> </ul> <script>
var json = [{ id:1, link:"http://www.baidu.com", img:"../大作业/images/2.png", content:"这是content", time:"2019-09-10" }, { id:2, link:"http://www.baidu.com", img:"../大作业/images/2.png", content:"这是content", time:"2019-09-10" }, { id:3, link:"http://www.baidu.com", img:"../大作业/images/2.png", content:"这是content", time:"2019-09-10" }]; var c = { data:json, date:"dddd" };
var jlist = document.querySelector(".jlist"); for(let i=0;i<json.length;i++){ let hang = ` <a href="${json[i].link}"> <img src="${json[i].img}" alt=""> <p class="name">${json[i].content}</p> <p class="time">${json[i].time}</p> </a> `; let li = document.createElement("li"); li.innerHTML = hang; jlist.appendChild(li);
} </script> </body> </html>
|