您好,我已在 KendoUI 网格的工具栏上添加了一个按钮,但我有几个问题,希望有人可以提供帮助。
未捕获的引用错误:未定义 sendEmail。
我不明白为什么它没有看到我的功能。仅出于测试目的,我会显示警报,直到它看到为止。
toolbar: [
{ name: "create", text: "Add" },
{ template: "<input type='button' class='k-button' value='Email Users' onclick='sendEmail()' />",
imageclass: "k-icon k-i-pencil" }
]
function sendEmail() {
debugger;
alert('Send Emails');
}
有人可以帮忙吗?
您可以使用如下:
toolbar: [
{
name: "Add",
text: "Send Email",
click: function(e){alert('Send Emails'); return false;}
}
],
根据文档,您需要返回您希望在单击时发生的功能。像这样:
template: '<a class="k-button" href="\\#" onclick="return toolbar_click()">Command</a>'
我希望有帮助。
这对我有用:
grid.find(".k-grid-toolbar").on("click", ".k-grid-myButton", function (e) { 警报(“工作了”);});
有很多方法可以使用它。请使用下面的例子。
toolbar: [
//{ template: kendo.template($("#k-tmpl-toolbar").html()) },
{ name: "Add", template: kendo.template("<button class='k-button k-button-sm k-rounded-md k-button-solid k-button-solid-primary' onclick='AddNewRecord()'>Add New</button>") },
{ name: "search" },
//{ name: "create", title: "New" },
],
你的函数sendEmail()是在document.ready中初始化的还是$(()=>{});如果没有,您将必须初始化它,否则您可以使用这种方式 为按钮添加一个 id 并将其写入 document.ready 中(从按钮标签中删除 onlcick)。
$("#examplebuttonid").click(()=>{
//write your code in here
});