<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" pageEncoding="UTF-8"%>
<script type="text/javascript" src='<c:url value="/dwr/engine.js"/>'></script>
<script type="text/javascript" src='<c:url value="/dwr/util.js"/>'></script>
<html>
<head>
<title>dwrTest</title>
<script type="text/javascript">
var cellFuncs2 = [//获取行数据
function(data) { return count++; },
function(data) { return data; },
function(data) {
return "<input type='text' name='Test' />";
},
function(data) {
return "<input id='delete' type='button' value='Delete' οnclick=\'delRow(this)\'/>";
}
];
function clickAdd(){
DWRUtil.addRows("table2",
["测试行"+count],//行数据要根据这里来获取数据
cellFuncs2, //获取行数据的函数
{ escapeHtml:false }
);
}
//删除全部
function clearRows(){
DWRUtil.removeAllRows("table2");
}
//删除行
function delRow(obj)
{
var tr = obj.parentElement.parentElement;
var tb = tr.parentElement.parentElement;//table标签和tr标签隐式存在一个tbody
tb.deleteRow(tr.rowIndex);
}
</script>
<body>
<input type="button" name="button3" value="AddRows" οnclick="clickAdd()"/>
<input type="button" name="button4" value="ClearRows" οnclick="clearRows()"/>
<table width="600" border="1" height="30">
<thead>
<tr>
<td>id</td>
<td>name</td>
<td>input</td>
<td>action</td>
</tr>
</thead>
<tbody id="table2">
<tr>
<td>0</td>
<td>名称</td>
<td><input type="text" name="a" id="a"/></td>
<td>
<input id="delete" type="button" value="Delete" οnclick="delRow(this)"/></td>
</tr>
</tbody>
</table>
</body>
</html>