gpt4 book ai didi

javascript - javascript 代码中的 anchor 标记 onclick 函数

转载 作者:行者123 更新时间:2023-11-28 06:58:20 26 4
gpt4 key购买 nike

我使用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();
}

但我收到此错误:

Uncaught ReferenceError: check is not definedonclick @ 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());
}

我在页面加载时使用它来创建数组。并通过注册事件将服务器端变量传递给客户端。

最佳答案

就用这个。它将工作:jsfiddle.net/sherali/W4Km8/6080

window.check = function() { alert("Goood"); } 

关于javascript - javascript 代码中的 anchor 标记 onclick 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32371533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com