JQuery小知识点(笔记)

关于给table的列添加参数,并指定传递参数

var currPage = 1;
var totalCount;
var dataLIst = [];
function data(curr, limit) {
    /*拿到总数据*/
    totalCount = testboke.data.total; //取出来的是数据总量
    dataLIst = testboke.data.records; // 将数据放到一个数组里面(dataLIst 还未声明,莫着急)
    pageCount = testboke.data.pages;
    createTable(curr, limit, totalCount);
};
/*创建的是一个表格,并将数据放进去*/
function createTable(currPage, limit, total) {
    var html = [],
        showNum = limit;
    if(total - (currPage * limit) < 0) showNum = total - ((currPage - 1) * limit);
    dataLIst.forEach((item,index)=>{
        html +=`<tr >
                <td>${item.companyName}</td>
                <td>${item.id}</td>
                <td>${item.pname}</td>
                <td>${item.ptypeName}</td>
                <td>${item.userName}</td>
                <td>${item.companyName}</td>
                <td>${item.companyName}</td>
                <td>${item.companyName}</td>
                <td><button class="btn-link btn edit" οnclick="handleEdit('${index}')">编辑</button> 
                    <button class="btn-link btn delete" id="${index}">删除</button>
                </td>
            </tr>`
    });
    $(`.tbody`).append(html);
};
function handleEdit(index){
    console.log(dataLIst[index]); // 获取当前行的数据
    window.location.href = "../expert/edit.html"; // 页面跳转
}
$(document).on("click",'.delete',function(x,y){
    console.log(x.target.id)
});
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页