bootStrap select 和 th:each 结合

   <div class="form-group"><!--for="firstname3" -->
                    <label class="col-sm-2 control-label">生产商</label>
                  <!--<input type="text" class="form-control" id="firstname3" name="producer.pid" placeholder="请输入厂家"  >-->

                       <select name="producer.pid">
                          <option value="">&#45;&#45;&#45;&#45;请选择-&#45;&#45;&#45;</option>
                           <ul th:each="A:${producers}">
                           <option  th:value="${A.pid}" th:text="${A.pname}"></option>
                           </ul>
                        </select>

                </div>

 

转载于:https://my.oschina.net/u/3566463/blog/1476651

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进行美化一下
04-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值