jquery遍历数组添加行删除行

<script language="javascript" type="text/javascript">

function queryInfo() {
var membercode = $('#membercode').val();
if(''== $.trim(membercode)){
alert('请填写会员编号!');
return false;
}
removeTr();
var formUrl = '${rc.contextPath}/debitLimitMgt/queryList.htm?method=queryList';
$.ajax({
url : formUrl,
type : 'POST',
dataType : 'json',
data : {'membercode': membercode},
async : false,
success : function(returnMsg) {
addTr(returnMsg);
},
error: function(jqXHR, textStatus, errorMsg){
alert("请求失败:" + errorMsg);
}
});
}

function removeTr(){
var rows=$("#dataList").find("tr").length;
if(rows>1){
for(var i=1;i<rows;i++){
$("#dataList tr").eq(i).remove();
}
}
}

function addTr(data){
$.each(data,function(i,obj){
var trHtml = '<tr><td>'+obj.membercode+'</td><td>'+obj.memberName+'</td><td>'+
obj.idContent+'</td><td>'+obj.memberType+'</td><td>'+
obj.openDebit+'</td><td>'+obj.singleLimit+'</td><td>'+
obj.batchLimit+'</td><td>'+obj.filterNum+'</td><td><tr>';
$("#dataList tr:last").after(trHtml);
})
}
</script>

posted @ 2017-11-07 16:39  四毛小师傅  阅读(1066)  评论(0编辑  收藏  举报