我使用jquery创建了一个动态表, 现在我想用链接编辑该表, 我写这样的onclick函数:
var array = $.parseJSON(arr);
debugger
for (var i = 0; i < array.length; i++) {
var row = "<tr>"
+ "<td>" + array[i].ID + "</td>"
+ "<td>" + array[i].Name + "</td>"
+ "<td>" + array[i].FatherName + "</td>"
+ "<td>" + array[i].RollNo + "</td>"
+ "<td>" + array[i].Age + "</td>"
+ "<td>" + array[i].Phone + "</td>"
+ "<td>" + array[i].Address + "</td>"
+ "<td><a href='#' onclick='check()'>Edit</a></td>"
+ "<td><a href='#'>Delete</a></td>"
+ "</tr>"
$("#table").append(row);
}
function hideStudents() {
$("#students").hide();
}
但是我收到了这个错误:
未捕获的ReferenceError:未定义检查单击@ StudentManagement.aspx:1
protected void Page_Load(object sender, EventArgs e)
{
BLLayer std = new BLLayer();
list = std.GetAllStudents();
var json = JsonConvert.SerializeObject(list);
//hfListData.Value = json;
StringBuilder strScript = new StringBuilder();
strScript.Append("<script type=\"text/javascript\">");
strScript.Append("var arr='");
strScript.Append(json);
strScript.Append("';");
strScript.Append("</script>");
ClientScriptManager script = Page.ClientScript;
if (!script.IsClientScriptBlockRegistered(this.GetType(), "Var"))
{
script.RegisterClientScriptBlock(this.GetType(), "Var", strScript.ToString());
}
我在页面加载时使用它来创建数组。并通过注册事件将服务器端变量传递给客户端。