html <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Dynamic HTML Table</title> <style> table, th, td { border: 1px solid black; border-collapse: collapse; padding: 5px; } </style> </head> <body> <button onclick="addRow()">Add Row</button> <table id="myTable"> <thead> <tr> <th th:text="#{column1}"></th> <th th:text="#{column2}"></th> <th th:text="#{column3}"></th> <th th:text="#{column4}"></th> <th th:text="#{column5}"></th> </tr> </thead> <tbody> <tr th:each="row, rowStat : ${rows}"> <td th:each="cell, cellStat : ${row}" th:onclick="'selectOption(this, ' + ${rowStat.index} + ', ' + ${cellStat.index} + ')'" th:text="${cell}"></td> </tr> </tbody> </table> <script> var rows = [[null, null, null, null, null]]; function addRow() { rows.push([null, null, null, null, null]); renderTable(); } function selectOption(cell, rowIndex, cellIndex) { var options = ["Option 1", "Option 2", "Option 3", "Option 4", "Option 5"]; var select = document.createElement("select"); for (var i = 0; i < options.length; i++) { var option = document.createElement("option"); option.value = options[i]; option.text = options[i]; select.appendChild(option); } cell.innerHTML = ""; cell.appendChild(select); rows[rowIndex][cellIndex] = select; } function renderTable() { var table = document.getElementById("myTable").getElementsByTagName('tbody')[0]; table.innerHTML = ""; for (var i = 0; i < rows.length; i++) { var row = table.insertRow(-1); for (var j = 0; j < rows[i].length; j++) { var cell = row.insertCell(j); if (rows[i][j] != null) { cell.appendChild(rows[i][j]); } else { cell.onclick = function() { selectOption(this, i, j) }; cell.innerHTML = "Click to Select"; } } } } renderTable(); </script> </body> </html>把这个页面用bootstrap进行美化一下
时间: 2023-06-10 11:03:12 浏览: 544
动态HTML表格">Dynamic HTML Table</th> </tr> </thead> <tbody> </tbody> </table> <script> function addRow() { var table = document.getElementById("myTable"); var row = table.insertRow(-1); var cell1 = row.insertCell(0); cell1.innerHTML = "New Row"; } </script> </body> </html>
这段代码是一个HTML页面,其中包含了一个动态的HTML表格。通过点击一个按钮,可以动态地在表格中添加一行。表格中包含一个表头和一个tbody,表头中只有一列。整个页面使用thymeleaf作为模板引擎,样式使用CSS定义。
相关问题
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="utf-8"> <title></title> </head> <body> <p th:text="${msg}"></p> <form method="post" action="/toAdd"> <p> 充值金额: <input type="text" name="moneyAdd" /> </p> <p> <button>提交</button> </p> </form> </body> </html>请帮我美化一下这个页面,要求可以适当增加色彩,调整版型
当然可以!为了美化这个页面,我们可以使用CSS来添加样式和颜色。以下是对给定HTML代码进行美化的示例:
```html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>美化页面</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
color: #333;
}
form {
background-color: #fff;
max-width: 400px;
margin: 0 auto;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
p {
margin-bottom: 10px;
}
input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
padding: 10px 20px;
background-color: #4caf50;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>美化页面示例</h1>
<p th:text="${msg}"></p>
<form method="post" action="/toAdd">
<p>
充值金额: <input type="text" name="moneyAdd" />
</p>
<p>
<button>提交</button>
</p>
</form>
</body>
</html>
```
在上面的示例中,我们添加了一些CSS样式来美化页面。我们设置了整个页面的背景颜色、页面标题的样式、表单的样式以及输入框和按钮的样式。你可以根据需要进行修改和调整。希望这可以帮助到你!
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>登录成功</title> </head> <body> <a> 登录成功的用户名:<span th:text="${username}"></span> </a><br> <a> 登录成功的用户信息:<span th:text="${userJson}"></span> </a><br> <a href="index.html">返回首页</a><br> </body> </html> 中的${username}报错
这是一个Thymeleaf模板,${username}应该是一个在Java后台代码中设置的变量,但是在模板中没有找到对应的值。你需要在Java代码中将该变量设置为正确的值,例如:
```java
model.addAttribute("username", "John");
```
这样,在模板中就可以使用${username}来显示"John"了。请检查你的Java代码是否正确设置了该变量。
阅读全文