javascript 在 Kendo UI 中单击自定义工具栏时如何调用函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11943056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call a function when custom toolbar is clicked in Kendo UI?
提问by Johndave Decano
I want to create a custom toolbar. Here is my code:
我想创建一个自定义工具栏。这是我的代码:
toolbar:[{
text: "Go to Add User Page",
className: "k-grid-custom",
imageClass: "k-add"
}],
function createUser(){
alert('Hello World');
}
I want to call the function named createUser when this button(custom toolbar) is clicked. How to make it possible?
单击此按钮(自定义工具栏)时,我想调用名为 createUser 的函数。如何使它成为可能?
回答by Jesper
You could add a unique class to the button and then use that class to bind to the click event.
您可以向按钮添加一个唯一的类,然后使用该类绑定到单击事件。
toolbar:[{
text: "Go to Add User Page",
className: "myCustomClass",
imageClass: "k-add"
}],
$(".myCustomClass").click(function() {
alert("Click!");
});
回答by Johndave Decano
function test(e){
return '<a class="k-button" href="#" id="toolbar-add_user" onclick="test_fn()">Add User</a>';
};
function test_fn(){
window.location = "http://www.google.com";
};
toolbar:[{
name:'add_user',
template:'#= test()#'
}],
- First i had to make a function to be able to customize the button and add an onclick event.
- Then i had to make a new function to listen to the event.
- 首先,我必须创建一个函数才能自定义按钮并添加一个 onclick 事件。
- 然后我不得不创建一个新函数来监听事件。