This article mainly introduces the function of jQuery ajax to dynamically generate tables, and analyzes the related operation skills of jQuery to dynamically create tables based on ajax data interaction based on specific examples. Friends who need it can refer to it. I hope it can help everyone.
$(function(){ ajaxT(); }); function ajaxT(){ $.ajax({ type:"POST", dataType: "json", url:"<%=basePath%>UserInfoServlet", data:"doaction=userList", success:function(data){ createShowingTable(data); } } ); } //动态的创建一个table function createShowingTable(data) { var tableStr = "<table class='tab-list' width='99%'>"; tableStr = tableStr + "<tr class='list-header'>" +"<td width='5%'>序号</td>" +"<td width='5%'><input id='checkAll' name='checkAll' type='checkbox' /></td>" +"<td width='30%'>用户姓名</td>" +"<td width='20%'>工号</td>" +"<td width='20%'>职位</td>" +"<td width='20%'>创建时间</td>" +"</tr>"; var len = data.length; for ( var i = 0; i < len; i++) { tableStr = tableStr + "<tr>" +"<td>"+ (i+1) + "</td>" +"<td><input class='check' id='checkOne' name='checkOne' type='checkbox' value='"+data[i].key+"' /></td>" +"<td>"+ data[i].realName + "</td>" + "<td>"+ data[i].userNo + "</td>" + "<td>"+ data[i].position + "</td>" +"<td>"+data[i].regTime+"</td>" +"</tr>"; } if(len==0){ tableStr = tableStr + "<tr style='text-align: center'>" +"<td colspan='6'><font color='#cd0a0a'>"+ 暂无记录 + "</font></td>" +"</tr>"; } tableStr = tableStr + "</table>"; //添加到p中 $("#tableAjax").html(tableStr); }
Related recommendations:
Sample analysis of php dynamically generating objects based on string class names
Asp for dynamically generating HTML forms. net method code example
js Dynamically generate html trigger event parameter character escaping example
The above is the detailed content of Sharing examples of jQuery's ajax dynamically generated table function. For more information, please follow other related articles on the PHP Chinese website!