gpt4 book ai didi

javascript - 将点击事件绑定(bind)到 Kendo ToolBar

转载 作者:行者123 更新时间:2023-12-03 22:50:13 26 4
gpt4 key购买 nike

我正在尝试将单击事件绑定(bind)到剑道工具栏中的按钮。我正在使用模板创建按钮。我正在将 Kendo Jquery 与 Angular 一起使用。任何帮助将不胜感激。

到目前为止,我已经使用 Kendo Jquery 文档尝试过此操作:

<!DOCTYPE html>
<html>

<head>
<base href="https://demos.telerik.com/kendo-ui/toolbar/index">
<style>
html {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
}
</style>
<title></title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.default-v2.min.css" />

<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/kendo.all.min.js"></script>

</head>

<body>
<div id="example">
<div class="demo-section k-content wide">
<div id="toolbar"></div>
</div>
<script>
$(document).ready(function () {
$("#toolbar").kendoToolBar({
items: [
{
template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-save'></span>Save</a>"
},
{
template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-arrows-swap'></span>Top/Bottom</a>"
},
{
template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-pencil'></span>Edit</a>"
},
{
template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-calendar'></span>Schedule</a>",
click: onButtonClick()
},

{
type: "splitButton",
text: "Download",
menuButtons: [{
text: "PDF",
icon: "k-i-pdf"
},
{
text: "EXCEL",
icon: "k-i-excel"
}
]
},

{
type: "button",
text: "Action",
overflow: "always"
},
{
type: "button",
text: "Another Action",
overflow: "always"
},
{
type: "button",
text: "Something else here",
overflow: "always"
}
]
});

$("#dropdown").kendoDropDownList({
optionLabel: "Paragraph",
dataTextField: "text",
dataValueField: "value",
dataSource: [{
text: "Heading 1",
value: 1
},
{
text: "Heading 2",
value: 2
},
{
text: "Heading 3",
value: 3
},
{
text: "Title",
value: 4
},
{
text: "Subtitle",
value: 5
}
]
});
});

function onButtonClick() {
alert('clicked')
}
</script>
</div>
</body>

</html>

Dojo 相同:https://dojo.telerik.com/@amitdwivedi/uDOFeWev

最佳答案

根据Telerik Docs for the toolbar Click function ,单击事件处理程序仅适用于 buttonsplitButton 类型的工具栏项。但是,items with a template do not have a type .

因此,您需要使用基本按钮而不是模板(然后您可以使用 Telerik 点击处理程序),或者将点击处理程序放入模板本身中,如下所示:

$(document).ready(function() {
$("#toolbar").kendoToolBar({
items: [
{
template: "<a href='' onclick='onButtonClick()' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-save'></span>Save</a>"
// ^^^^^^^^^^^^^^^^^^^^^^^^^
}
]
});
});

function onButtonClick(){
alert('clicked')
}

Dojo 示例:https://dojo.telerik.com/UniqiHuF/4

关于javascript - 将点击事件绑定(bind)到 Kendo ToolBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58852347/

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