为什么我不能在 jQuery 中初始化我的变量?
Why I can not initialize my variable in jQuery?
我在我的应用程序中冻结了。我想使用函数之类的变量创建自己的 reports.js 文件,但我无法对其进行初始化。我正在复制模板中已经完成的其他内容,但我不明白为什么我的不起作用。
这是我将其称为头部部分的部分。
$(document).ready(function(){
"use strict";
App.init(); // Init layout and core plugins
Plugins.init(); // Init all plugins
FormComponents.init(); // Init all form-specific plugins
Reports.init();
$('#StartDate').pickadate({
formatSubmit: 'yyyy/mm/dd',
hiddenName: true
});
});
当我 运行 站点时,控制台显示
TypeError: Reports.init 不是函数
现在我要分享 report.js 文件:
var Reports = function () {
"use strict";
var form = $('form').attr('id');
alert(form);
/* * * * * * * * * * * * * * *
* Employee Clock-In Clock-Out
* * * * * * * * * * * * * * */
var EmployeeClocks = function(form) {
// will do something
}
return {
// main function to initiate reports
init: function () {
// EmployeeClocks();
},
};
}
添加 ()
。您的 Reports
现在是一个函数,而不是 class。但是这个函数returns就是你想要的东西
var Reports = function () { ... }()
$(document).ready(function(){
"use strict";
App.init(); // Init layout and core plugins
Plugins.init(); // Init all plugins
FormComponents.init(); // Init all form-specific plugins
// Reports.init();
var reports = new Reports();
reports.init();
$('#StartDate').pickadate({
formatSubmit: 'yyyy/mm/dd',
hiddenName: true
});
});
我在我的应用程序中冻结了。我想使用函数之类的变量创建自己的 reports.js 文件,但我无法对其进行初始化。我正在复制模板中已经完成的其他内容,但我不明白为什么我的不起作用。
这是我将其称为头部部分的部分。
$(document).ready(function(){
"use strict";
App.init(); // Init layout and core plugins
Plugins.init(); // Init all plugins
FormComponents.init(); // Init all form-specific plugins
Reports.init();
$('#StartDate').pickadate({
formatSubmit: 'yyyy/mm/dd',
hiddenName: true
});
});
当我 运行 站点时,控制台显示 TypeError: Reports.init 不是函数
现在我要分享 report.js 文件:
var Reports = function () {
"use strict";
var form = $('form').attr('id');
alert(form);
/* * * * * * * * * * * * * * *
* Employee Clock-In Clock-Out
* * * * * * * * * * * * * * */
var EmployeeClocks = function(form) {
// will do something
}
return {
// main function to initiate reports
init: function () {
// EmployeeClocks();
},
};
}
添加 ()
。您的 Reports
现在是一个函数,而不是 class。但是这个函数returns就是你想要的东西
var Reports = function () { ... }()
$(document).ready(function(){
"use strict";
App.init(); // Init layout and core plugins
Plugins.init(); // Init all plugins
FormComponents.init(); // Init all form-specific plugins
// Reports.init();
var reports = new Reports();
reports.init();
$('#StartDate').pickadate({
formatSubmit: 'yyyy/mm/dd',
hiddenName: true
});
});