jquery给页面添加标签
1.动态添加 没有判断的
for(var i=0;i<data.list.length;i++){
var $str=$("<tr id='delTr"+data.list[i].id+"'></tr>");
$("section>table").append($str)
$str.append("<td>"+data.list[i].id+"</td>")
.append("<td>"+data.list[i].title+"</td>")
.append("<td>"+data.list[i].summary+"</td>")
.append("<td>"+data.list[i].uploaduser+"</td>")
.append("<td>"+data.list[i].createDate+"</td>")
.append("<td><a href='update.html?entryId="+data.list[i].id+"'>修改</a>" +
"<a href='#' id='del"+data.list[i].id+"' del='"+data.list[i].id+"'>删除</a></td>");
}
2.动态添加 需要有判断的
function initPageInfo() {
var role =$("#providerId").val();
var queryProductName = $("#queryProductName").val();
var queryProviderId = $("#providerId").val();
var queryIsPayment = $("#isPay").val();
if (queryProductName==""){
queryProductName=null;
}
if (queryProviderId==""){
queryProviderId=0;
}
if (queryIsPayment==""){
queryIsPayment=0;
}
console.log(queryIsPayment+queryProductName+queryProviderId);
var params = "queryProductName="+queryProductName+"&queryProviderId="+queryProviderId+"&queryIsPayment="+queryIsPayment;
console.log(params);
$.getJSON("/provider/doBill",params,success);
function success(data){
console.log("data==="+data);
$("#queryProviderId").html("");
for (var i=0;i<data.providerList.length;i++){
if (data.providerList[i].id==parseInt(role)){
$("#queryProviderId").append("<option selected ='selected' value='"+data.providerList[i].id+"'>"+data.providerList[i].proName+"</option>");
}else {
$("#queryProviderId").append("<option value='"+data.providerList[i].id+"'>"+data.providerList[i].proName+"</option>");
}
}
$("#providerTable tr:gt(0)").remove();
for(var i=0;i<data.billList.length;i++){
var $tr = $("<tr ></tr>");
$("#providerTable").append($tr);
var k = data.billList[i];
$tr.append('<td>'+data.billList[i].billCode+'</td>')
.append('<td>'+data.billList[i].productName+'</td>')
.append('<td >'+data.billList[i].proName+'</td>')
.append('<td>'+data.billList[i].productcount+'</td>')
if (data.billList[i].ispayment==1){
$tr.append('<td >已付款</td>')
}else if(data.billList[i].ispayment==2){
$tr.append('<td >未付款</td>')
}
$tr.append('<td>'+data.billList[i].creationdate+'</td>')
.append('<td><a href="http://localhost:8080/provider/updateBill?id='+data.billList[i].id+' "><img src="/statics/images/xiugai.png" alt="修改" title="修改"/></a> ' +
'<a href="#" id="deleteId'+data.billList[i].id+'" deleteId="'+data.billList[i].id+'"><img src="/statics/images/schu.png" alt="删除" title="删除"/></a>' +
'<span><a class="viewUser" href="http://localhost:8080/provider/billView?id='+data.billList[i].id+' " ><img src="/statics/images/read.png" alt="查看" title="查看"/></a></span></td>');
}
}
}