Javascript 使用bind调用click函数?
我有点击功能,如:Javascript 使用bind调用click函数?,javascript,jquery,Javascript,Jquery,我有点击功能,如: <script type="text/x-kendo-template" id="template"> <div class="toolbar"> <button id="ExportExcel" class="btn btn-default " onclick="ExportExcel(); return false;"><i class="fa fa-file-excel-o">&l
<script type="text/x-kendo-template" id="template">
<div class="toolbar">
<button id="ExportExcel" class="btn btn-default " onclick="ExportExcel(); return false;"><i class="fa fa-file-excel-o"></i> Exportar</button>
</div>
</script>
它是有效的,但现在我需要改变我的函数,我有一些类似的东西:
var exportFlag = false;
$("#lstEmployees").data("kendoGrid").bind("ExportExcel", function (e) {
if (!exportFlag) {
// e.sender.showColumn(0); for demo
// for your case show column that you want to see in export file
e.sender.showColumn(2);
e.preventDefault();
exportFlag = true;
setTimeout(function () {
e.sender.saveAsExcel();
});
} else {
e.sender.hideColumn(5);
e.sender.hideColumn(6);
exportFlag = false;
}
});
但我有一个问题:
未捕获的TypeError:无法读取未定义的属性“bind”
怎么了?如何调用onclick Export excel作为类似于工作示例的函数?关于它看起来像$(“#lstmemployees”)。数据(“kendoGrid”)不会返回任何内容。运行此网格时是否存在?
$(“#lstmemployees”)。数据(“kendoGrid”)
将返回一个对象/值。这可能不是jquery对象<代码>绑定()在jquery对象上可用。是的,它会向我导出一个Excel,但我想更改以获取隐藏值,如下面的答案@Alexandro,以及如何使用函数运行它,如此问题的答案@sam@JesusA. 你能分享一个工作代码吗?这将有助于我们理解这一点。看起来美元(“#lstmemployees”)。数据(“kendoGrid”)不会返回任何内容。运行此网格时是否存在?$(“#lstmemployees”)。数据(“kendoGrid”)
将返回一个对象/值。这可能不是jquery对象<代码>绑定()在jquery对象上可用。是的,它会向我导出一个Excel,但我想更改以获取隐藏值,如下面的答案@Alexandro,以及如何使用函数运行它,如此问题的答案@sam@JesusA. 你能分享一个工作代码吗?这将有助于我们理解这一点。
var exportFlag = false;
$("#lstEmployees").data("kendoGrid").bind("ExportExcel", function (e) {
if (!exportFlag) {
// e.sender.showColumn(0); for demo
// for your case show column that you want to see in export file
e.sender.showColumn(2);
e.preventDefault();
exportFlag = true;
setTimeout(function () {
e.sender.saveAsExcel();
});
} else {
e.sender.hideColumn(5);
e.sender.hideColumn(6);
exportFlag = false;
}
});