1> 我有剑道网格,其中一列有一个按钮。我已将 javascript 函数分配给按钮的 onclick 事件。 javascript 进行 ajax 调用。但是当我点击按钮时出现错误
0x800a138f - JavaScript 运行时错误:属性“DoSomething”的值为 null 或未定义,而不是 Function 对象
我尝试将 onclick 设置为“javascript:DoSomething();”没有运气
2> 如果可能的话,我还想将“BatchKey”值传递给函数
<div>
@(Html.Kendo().Grid< BatchDetail>()
.Name("grid")
.Columns(col =>
{
col.Bound(p => p.BatchKey);
col.Bound(p => p.OriginalCost);
col.Bound(p => p.Status);
col.Bound(p => p.LastFileName);
col.Bound(p => p.FileID).ClientTemplate(
"# if (Status == \"Error\") { #" +
"<button id=\"btnResolve\" class=\"resolve-button\" onclick=\"DoSomething();\">Resolve</button>" +
"#}#"
).Title("Action");
})
.AutoBind(true)
.Pageable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read
.Action("GetData", "Detail", new { ID = Model.ID })))
)
</div>
function DoSomething()
{
$.ajax({
url: "www.msn.com",
success: function (result)
{
$("#div1").html(result);
}
})
}
最佳答案
按钮ID需要是唯一的,所以你不能这样使用它。您可以像这样传递 BatchKey:
col.Bound(p => p.FileID).ClientTemplate(
"# if (Status == \"Error\") { #" +
"<button class=\"resolve-button\" onclick=\"DoSomething(this, '#= BatchKey #');\">Resolve</button>" +
"#}#"
).Title("Action");
function DoSomething(button, batchKey)
{
$.ajax({
url: "www.msn.com",
success: function (result)
{
$("#div1").html(result);
}
})
}
我已经在自己的网格上对此进行了测试,效果很好。如果仍然不起作用,则说明您发布的代码之外的代码存在问题。
关于javascript - 0x800a138f - JavaScript 运行时错误 : The value of the property '' is null or undefined, 不是函数对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29836042/