gpt4 book ai didi

javascript - 即使加载了 JavaScript,也无法调用加载的 JavaScript 中的变量

转载 作者:行者123 更新时间:2023-11-28 04:14:33 25 4
gpt4 key购买 nike

谁能帮我解决这个问题吗?

如果我有这个工作示例:

var Login = function() {

var handleLogin = function() {//code here

}

var handleForgetPassword = function() {//code here
}

var handleRegister = function() {//code here
}

return {
init: function() {

handleLogin();
handleForgetPassword();
handleRegister();

}

};

}();

jQuery(document).ready(function() {
Login.init();
});

但是下一个示例给出了错误。即使我确定文件已加载。我无法确定该函数的范围。

<script src="javascriptLoginfile.js" type="text/javascript"></script>
<script>
jQuery(document).ready(function() {
Login.init();
});
</script>

错误

Uncaught ReferenceError: Login is not defined at HTMLDocument. (login:160) at i (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2) at Function.ready (jquery.min.js:2) at HTMLDocument.K (jquery.min.js:2)

最佳答案

对我有用。

var Login = function() {

var handleLogin = function() { //code here
console.log('handleLogin');
}

var handleForgetPassword = function() { //code here
console.log('handlForgetPassword');
}

var handleRegister = function() { //code here
console.log('handleRegister');
}

return {
init: function() {

handleLogin();
handleForgetPassword();
handleRegister();

}

};

}();

jQuery(document).ready(function() {
Login.init();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

关于javascript - 即使加载了 JavaScript,也无法调用加载的 JavaScript 中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45975426/

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