如果添加行数据的时候,前面编辑清空,记得在添加的formatter的input里给value绑定值, value="' + value + '"
博客参考链接
下面的代码调试通过(IE),确保没有问题:<table border=1 id=tab1></table>
<input type=button onclick="f_add()" value="添加">
<script type=text/javascript>
var id=1
function f_del(x){
for (i=0i<tab1.rows.lengthi++)
if (x==parseInt(tab1.rows[i].cells[0].innerHTML))
{tab1.deleteRow(i)break}
}
function f_add(){
n=tab1.rows.length
r=tab1.insertRow(n)
r.insertCell(0).innerHTML='<button onclick=f_del('+id+')>删除</button>'
r.insertCell(0).innerHTML=id
id++
}
f_add()
</script>
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="gb2312">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>123</title>
<script src="Scripts/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var spotMax = 30
if($('div.spot').size() >= spotMax) {$(obj).hide()}
$("input#add").click(function(){ addSpot(this, spotMax)
})
})
function addSpot(obj, sm) {
$('div#spots').append(
'<div>' +
'<span><input name="shengfen" type="text" /></span>'+
'<span><input name="diqu" type="text" /></span>'+
'<input type="button" class="remove spot01" value="删除行" /></div>')
.find("input.remove").click(function(){
$(this).parent().remove()
$('input#add').show()
})
if($('div.spot').size() >= sm) {$(obj).hide()}
}
</script>
</head>
<body>
<span><input name="shengfen" type="text" /></span>
<span><input name="diqu" type="text" /></span>
<input type="submit" id="add" name="Submit" value="添加行" >
<div>
<form method="post" name="asdf" id="asdf"><div id="spots"></div></form>
</div>
</body>
</html>
效果这样(样式再自己调)
要加jQuery插件进去
不懂再追问
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)