因此,我尝试使用JavaScript在表格行中添加额外的输入字段,但似乎无法弄清楚。我现在的方法是每次有人单击“添加更多”按钮时,仅插入额外的html代码并添加新的表格行。这是我的代码
的HTML
<div class="set-form">
<table class="table table-bordered">
<tr>
<th>Question</th>
<th>Answer</th>
</tr>
<tr>
<td>
<textarea name="Question" placeholder="Question" th:field="${questionAnswerSet.question}" id="question" style="resize: none; width: 100%;"></textarea>
</td>
<td>
<textarea name="Answer" placeholder="Answer" th:field="${questionAnswerSet.answer}" id="answer" style="resize: none; width: 100%;"></textarea>
</td>
</tr>
</table>
<div class="set-form">
<input type="button" id="more_fields" onclick="add_fields();" value="Add More" class="btn btn-info" />
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的JavaScript
function add_fields() {
document.getElementById('set-form').innerHTML += '<tr> < td > < textarea name = "Question"
placeholder = "Question"
th: field = "${questionAnswerSet.question}"
id = "question"
style = "resize: none; width: 100%;" > …Run Code Online (Sandbox Code Playgroud) 因此,我尝试使用 th:href 重定向整个网址,但它添加了我不想要的字符。
我当前的网址是这个
http://localhost:8080/viewCourse/post/5
Run Code Online (Sandbox Code Playgroud)
我试图回溯到该帖子所属的课程,即
http://localhost:8080/viewCourse/1
Run Code Online (Sandbox Code Playgroud)
所以目前这就是我的 html 的样子
<a th:href="@{'/viewCourse/'(${post.course.id})}"><span th:text="${post.course.name}"></span></a>
Run Code Online (Sandbox Code Playgroud)
这是我得到的网址
http://localhost:8080/viewCourse/?1
Run Code Online (Sandbox Code Playgroud)
Id 是正确的,但我不确定为什么会?在那里。
我也尝试过这个
<a th:href="@{'/viewCourse/'(id=${post.course.id})}"><span th:text="${post.course.name}"></span></a>
Run Code Online (Sandbox Code Playgroud)
这给了我这个
http://localhost:8080/viewCourse/?id=1
Run Code Online (Sandbox Code Playgroud)
如果有人能看到我如何解决这个问题并让我知道那就太好了,提前致谢。