动态生成表格的每一行的操作按钮如何获取当前行的index

for(var i=0; i<10; i++) {
    $("#tableList").append(
        $("<tr>").append(
            $("<td>").append(
                $("<input>").attr({"type": "text", "value": defalutVal[i].PassScore})
            )
        ).append(
            $("<button>").bind("click",{index: i}, function(e) {
                console.log("----e.data.index-----",e.data.index) //即为i的值 
            })
        )
    )
}        

若是直接使用$("<button>").click(function() { }),获取到的值为i的最大值加1,使用bind函数的第二参数可以去到表格的某一行的index。

原文地址:https://www.cnblogs.com/cxuer/p/7521960.html