Java SpringBoot thymeleafを使ってものすごく簡単なアプリケーションを作成したい
HTML、Thymeleaf,javascriptを使用している環境です。
テーブルタグを使い、java側で固定の値を設定し、その値をテーブルタグで描画しています。
今のテーブルタグは3行ですが、+ボタンを押すことで
私が試したのは以下のコードで、行の追加はできるのですがテキストボックスの追加の仕方をどのように
すれば反映されるのかが検討つきません
<script language="javascript"> function addList(id) { var table = document.getElementById("personList") var rows = table.insertRow(-1); } </script>
以下私が作成したフロント側のコードです
HTML、Thymeleaf,javascript
1<!DOCTYPE HTML> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4<title>Top page</title> 5<meta http-equiv="Content-Type" 6 content="text/html;charset=UTF-8"/> 7<style> 8body { font-size:13pt; color:gray; margin:5px 25px; } 9pre { font-size:13pt; color:gray; padding:5px 10px; border:1px; solid gray; } 10</style> 11</head> 12<body> 13 <form th:action="@{/confirm}" th:object="${IndexForm}" method="post"> 14 <table id="personList"> 15 <tr> 16 <th>NAME</th> 17 <th>AGE</th> 18 <th>HOBBY</th> 19 </tr> 20 <tr th:each="person:${personList}"> 21 <td th:text="${person.name}"></td> 22 <td th:text="${person.age}"></td> 23 <td><input type="text" class="form-control" name="test" th:value="${person.hobby}" /></td> 24 </tr> 25 </table> 26 <button type="button" id="addrow" onclick="addList(this);">+</button> 27 <button type="submit" id="confirm" >confirm</button> 28 </form> 29</body> 30<script language="javascript"> 31function addList(id) { 32 var table = document.getElementById("personList") 33 var rows = table.insertRow(-1); 34 } 35 </script> 36</html>
テーブルの行の中でテキストボックスの追加がわかる方いらっしゃいましたらご教授お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/08 09:04
2017/08/08 09:07
2017/08/08 09:12