如何使用Handlebar.js向表中添加行
How to add row into the table using Handlebar.js
我对handlebar.js完全陌生,所以需要专家的帮助来完成我的任务。
我有一个已经通过jsp创建的Html表。现在我如何使用handlebar.js动态添加新行到表?
Html结构<table>
<tr>
<td class="one">one</td>
<td class="two">two</td>
<td class="three">three</td>
</tr>
<tr>
<td class="one">check</td>
<td class="two">checked</td>
<td class="three">checking</td>
</tr>
</table>
<form>
#input for first column
#input for second column
#input for third column
</form>
<div class="add">Add New Row</div> //on clicking add new row form gets open and there is save button to add new row
我相信这对Kunal来说已经晚了3年8个月,但也许有人会受益。
@Palpatim是正确的,一点jquery就可以了。我在我的车把视图中包含了以下内容:
按钮:
<button id="btnNewRow">Add New Row</button>
脚本向表中添加一行:
<script>
$(document).ready(function() {
$('#btnNewRow').on('click', function(evt) {
evt.preventDefault();
$("#approverTable").find('tbody')
.append($('<tr><td><input></td><td><input></td><td><input></td></tr>'))
});
});
</script>
最后请记住,您需要从本地副本或通过内容分发网络(CDN)加载jquery,因此添加以下内容(我在我的handlebars布局而不是我的视图中添加)。
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
相关文章:
- 如何在Google柱状图中动态添加行/列
- 使用jQuery动态添加表并在其中动态添加行
- 使用.on动态添加jquery/js不知道的html元素
- 属性未添加到JS对象
- 将重定向URL链接添加到JS函数
- Angularjs在当前行位置添加行
- 将Rails后端添加到JS/HTML/CSS应用程序时,正确的文件位置是什么
- 使用Moment添加天数.JS
- 在change事件javascript上动态添加行
- 当源工作表添加了行时,如何编写在一个工作表中添加行的脚本
- 添加行并运行多个mySQL查询
- 如何在引导程序中添加dropdown.js依赖项
- 使用JS向html表添加行
- 如何在文本框vue.js上根据指定的数字添加行
- 挖空.js - 对表求和,添加行并用 AJAX 填充表
- 想要使用js添加行onclick
- Js添加行(克隆)获取变量
- 如何使用Handlebar.js向表中添加行
- Node.js sqlite3 -动态添加行时出错
- 如何使用JS或angular JS在html中添加行后本地存储表