下面代码中
$(obj).parent().addClass("active"),测试的时候是正常的使用console.log($(obj).parent())来输出看到是有的,但是在页面上查看却并没有active这个class属性
如果使用
$("#wrapper ul").find("li").eq(pageNum+2).addClass("active"),在页面上是可以正常显示的,有哪位大神知道是怎么回事呢?
$.ajax({
url: ctx+"/aaa/abc",
dataType: "JSON",
type: "post",
data: getData,
success: function (o) {
if(o.list!=null){
pageSize=o.pageSize;
pageNum=o.pageNum;
var result=o.list;
for (let i = 0; i <result.length ; i++) {
$("#wrapper >table >tbody").append("<tr id="+result[i].houseId+"></tr>")
$("#"+result[i].houseId).append("<td>"+result[i].community+"</td>")
$("#"+result[i].houseId).append("<td>"+result[i].houseNum+"</td>")
$("#"+result[i].houseId).append("<td>"+result[i].address+"</td>")
$("#"+result[i].houseId).append("<td>"+result[i].houseOwner+"</td>")
$("#"+result[i].houseId).append("<td>"+result[i].ownerPhone+"</td>")
$("#"+result[i].houseId).append("<td>"+result[i].ownerCardType+"</td>")
$("#"+result[i].houseId).append("<td>"+result[i].ownerCardId+"</td>")
$("#"+result[i].houseId).append("<td>"+result[i].watermeter+"</td>")
$("#"+result[i].houseId).append("<td>"+result[i].gasmeter+"</td>")
if ($.trim(ctx)!="" || typeof (ctx)!="undefined" || ctx!=null) {
$("#" + result[i].houseId).append("<td>" +
"<a style='cursor:pointer' onclick='delHouse(" + result[i].houseId + ")'>删除</a>" +
" | " +
"<a style='cursor:pointer' onclick='editHouse(" +JSON.stringify(result[i]) + ")' data-toggle='modal' data-target='#myModal'>编辑</a>" +
"</td>");
} else {
$("#" + result[i].houseId).append("<td>" +
"<a style='cursor:pointer' onclick='delHouse(" + result[i].houseId + "," + ctx + ")'>删除</a>" +
" | " +
"<a style='cursor:pointer' onclick='editHouse(" + JSON.stringify(result[i]) + "," + ctx + ")' data-toggle='modal' data-target='#myModal'>编辑</a>" +
"</td>");
}
}
$("#wrapper").append('<nav style="text-align:center"></nav>');
$("#wrapper nav").append("<ul class='pagination'></ul>");
$("#wrapper ul").append('<li><a href="#">«</a></li>');
$("#wrapper ul").append('<li><a href="#">首页</a></li>');
$("#wrapper ul").append('<li><a href="#" onclick="prePage(this)">上一页</a></li>');
for (let i = o.navigatepageNums[0]; i <= o.navigateLastPage; i++) {
$("#wrapper ul").append('<li ><a href="#">'+i+'</a></li>');
}
$("#wrapper ul").append('<li><a href="#" onclick="nextPage(this)">下一页</a></li>');
$("#wrapper ul").append('<li><a href="#">末页</a></li>');
$("#wrapper ul").append('<li><a href="#">»</a></li>');
let li=$("#wrapper ul").find("li").eq(3).children("a").text();
if(li==o.pageNum){
$("#wrapper ul").find("li").eq(3).addClass("active")
}else{
$(obj).parent().addClass("active")
//$("#wrapper ul").find("li").eq(pageNum+2).addClass("active")
console.log($(obj).parent())
console.log("pageNum:"+pageNum)
console.log($("#wrapper ul"))
}
}
}
})