酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

品牌列表制作:作业要求: 1、使用原生js配合ecma的高级语法实现,不可以直接使用vue实现。(练习js和ecma) 2、点击添加功能可以在表格下面新增加一行 3、点击删除会出现确认框,如果点击确认就移除对应的这一行。 4、表格中时间的处理可以使用原生js,也可以根据提供的素材lib文件夹中的dayjs来实现

以下是一个使用原生 JavaScript 配合 ECMAScript 高级语法实现的品牌列表制作示例: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>品牌列表</title> </head> <body> <h2>品牌列表</h2> <table id="brandTable"> <tr> <th>品牌名称</th> <th>创建时间</th> <th>操作</th> </tr> </table> <button onclick="addBrand()">添加</button> <script> // 品牌数据数组 let brands = [ { name: "品牌 1", createTime: new Date() }, { name: "品牌 2", createTime: new Date() } ]; // 渲染表格 function renderTable() { let table = document.getElementById('brandTable'); table.innerHTML = '<tr><th>品牌名称</th><th>创建时间</th><th>操作</th></tr>'; for (let brand of brands) { let row = table.insertRow(); let nameCell = row.insertCell(0); let timeCell = row.insertCell(1); let actionCell = row.insertCell(2); nameCell.innerHTML = brand.name; timeCell.innerHTML = brand.createTime.toLocaleString(); let deleteBtn = document.createElement('button'); deleteBtn.innerHTML = '删除'; deleteBtn.onclick = function () { if (confirm('确定要删除这一行吗?')) { let index = brands.indexOf(brand); brands.splice(index, 1); renderTable(); } }; actionCell.appendChild(deleteBtn); } } renderTable(); // 添加品牌 function addBrand() { let name = prompt('请输入品牌名称:'); if (name) { brands.push({ name: name, createTime: new Date() }); renderTable(); } } </script> </body> </html> ``` 在上述示例中,我们使用了一个数组来存储品牌数据,通过 `renderTable` 函数来渲染表格,`addBrand` 函数用于添加新的品牌。当点击删除按钮时,会弹出确认框,确认后删除对应行并重新渲染表格。 [2024-11-13 17:42:19 | AI写代码神器 | 596点数解答]

相关提问