求一个动态添加tr的js,比较有难度 jshtml 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <table width="500px"> <thead> <tr> <td>1</td> <td>2</td> </tr> <tr> <td><input type="button" onclick="addRow()" value="create" /></td> <td><input type="button" onclick="removeRow()" value="remove" /></td> </tr> </thead> <tbody> </tbody> <tfoot> <tr> <td><input type="button" onclick="addRow()" value="create" /></td> <td><input type="button" onclick="removeRow_2()" value="remove" /></td> </tr> </tfoot></table> function addRow(){ $('table tbody').append( $('<tr>').append( $('<td>').text($('table tbody tr').length), $('<td>').html( $('<input>').attr("type","button") .attr("value","remove this") .click(function() { $(this).parents("tr:first").remove(); }) ) ) ); } function removeRow(){ $('table tbody tr:last').remove(); }你试试吧~ DEMO>>>>>>>>>>>>>http://jsfiddle.net/DKWnE/1/ //html 表格<table id='datatable'></table>建立一个数组 包含表格数据 一个元素 相当于包含一行trvar datas = [];一个方法添加数据(注意 添加数据只要修改 datas就可以了)function adddata(index){ //在第数组的第几行处添加数据 //代码自己写 //最后 renderer(datas); //重新刷新显示}一个方法删除数据(同上 只处理 datas)function deldata(index){ //删除数组指定索引的行 //代码自己写 //最后 renderer(datas); //重新刷新显示} 一个方法 吧数组渲染成表格function renderer(datas){ //这个还是自己写 就是dom插入操作么 for(var i=0;i<datas.length;i++){ var index = i;' //每行的按钮只要绑定 上面 adddata , deldata方法就可以了 }}//任何mvc东西 这样一拆分 应该很简单 showbo大神,帮我看看样式问题 My97DatePicker控件返回有效日期的问题 js动态创建对象 怎么获取该动态对象? Firefox加入收藏夹以后为什么默认总在sideBar打开? 怎麼樣搜索這個xml裡的節點? 大家帮帮忙,让把这句话改为内容加载完之后显示 贴一个JS的树形目录类吧,无限层次 (在线等待)请教打开窗口问题 谁能用最简单的方法作一个这样的东西:要求<input>中输入的是100内的数字,其他字符输入无效! 如何把数字写入表格 jquery用append添加了js代码碰到的问题 求大神帮忙改一下程序 js的打字游戏
<table width="500px">
<thead>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td><input type="button" onclick="addRow()" value="create" /></td>
<td><input type="button" onclick="removeRow()" value="remove" /></td>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td><input type="button" onclick="addRow()" value="create" /></td>
<td><input type="button" onclick="removeRow_2()" value="remove" /></td>
</tr>
</tfoot>
</table>
function addRow(){
$('table tbody').append(
$('<tr>').append(
$('<td>').text($('table tbody tr').length),
$('<td>').html(
$('<input>').attr("type","button")
.attr("value","remove this")
.click(function() {
$(this).parents("tr:first").remove();
})
)
)
);
}
function removeRow(){
$('table tbody tr:last').remove();
}
你试试吧~
<table id='datatable'></table>建立一个数组 包含表格数据 一个元素 相当于包含一行tr
var datas = [];一个方法添加数据(注意 添加数据只要修改 datas就可以了)
function adddata(index){ //在第数组的第几行处添加数据
//代码自己写
//最后
renderer(datas); //重新刷新显示
}
一个方法删除数据(同上 只处理 datas)
function deldata(index){ //删除数组指定索引的行
//代码自己写
//最后
renderer(datas); //重新刷新显示
} 一个方法 吧数组渲染成表格
function renderer(datas){
//这个还是自己写 就是dom插入操作么
for(var i=0;i<datas.length;i++){
var index = i;'
//每行的按钮只要绑定 上面 adddata , deldata方法就可以了
}
}
//任何mvc东西 这样一拆分 应该很简单