Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';从body onload调用函数(未捕获引用错误:未定义resetLoginForm)javascript_Javascript_Html - Fatal编程技术网

Can';从body onload调用函数(未捕获引用错误:未定义resetLoginForm)javascript

Can';从body onload调用函数(未捕获引用错误:未定义resetLoginForm)javascript,javascript,html,Javascript,Html,我有一个body onload在javascript中调用函数。我尝试了很多方法,但控制台只是打印到错误日志: 未捕获引用错误:未定义resetLoginForm 我的代码如下: <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <head> <title>Login Page</title> <

我有一个body onload在javascript中调用函数。我尝试了很多方法,但控制台只是打印到错误日志:

未捕获引用错误:未定义resetLoginForm

我的代码如下:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/html">

    <head>

        <title>Login Page</title>

        <script src="/client/js/popper.min.js"></script>
        <script src="/client/js/js.cookie.min.js"></script>
        <script src="/client/js/querystring.js"></script>
        <!--Import Google Icon Font-->
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <!--Import materialize.css-->
        <link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"  media="screen,projection"/>
        <!--Let browser know website is optimized for mobile-->
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <script type="module" src="js/login.js"></script>

    </head>

    <body class="blue-grey darken-2" onload="resetLoginForm()">

        <script src="js/jquery-3.3.1.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>

您正在使用新的ECMAScript模块(
),这些模块独立于它们自己的作用域。您的函数
resetLoginForm()
未在全局范围内定义(在全局范围内,您基本上可以从onload body函数调用它)。您需要在模块中明确定义它:

import * as Cookies from "/client/js/js.cookie.min.js";

window.resetLoginForm = {

    if (Cookies.get("destination") === undefined) {
        window.location.href = "/client/index.html";
    }
    ...
理想情况下,尽管,您根本不应该使用
onload
。只需在以下位置添加事件侦听器:

import * as Cookies from "/client/js/js.cookie.min.js";

function resetLoginForm() {

    if (Cookies.get("destination") === undefined) {
        window.location.href = "/client/index.html";
    }

    ...
}

// Attach an event, and call resetLoginForm when the document is done loading.
document.addEventListener("DOMContentLoaded", resetLoginForm);

您正在使用新的ECMAScript模块(
),这些模块独立于它们自己的作用域。您的函数
resetLoginForm()
未在全局范围内定义(在全局范围内,您基本上可以从onload body函数调用它)。您需要在模块中明确定义它:

import * as Cookies from "/client/js/js.cookie.min.js";

window.resetLoginForm = {

    if (Cookies.get("destination") === undefined) {
        window.location.href = "/client/index.html";
    }
    ...
理想情况下,尽管,您根本不应该使用
onload
。只需在以下位置添加事件侦听器:

import * as Cookies from "/client/js/js.cookie.min.js";

function resetLoginForm() {

    if (Cookies.get("destination") === undefined) {
        window.location.href = "/client/index.html";
    }

    ...
}

// Attach an event, and call resetLoginForm when the document is done loading.
document.addEventListener("DOMContentLoaded", resetLoginForm);
  • 更改是
  • 在onload中,请检查一次“重置登录信息”功能
  • 更改是
  • 在onload中,请检查一次“重置登录信息”功能

  • HTML似乎缺少带有这些ID的表单。哪个脚本名加载了上面的JS代码?HTML似乎缺少带有这些ID的表单。哪个脚本名加载了上面的JS代码?所以我添加了事件侦听器。从“/client/js/js.cookie.min.js”导入*作为cookie;给出一个错误,说明login.js:5 Uncaught TypeError:Cookies.get不是HTMLDocument.resetLoginForm(login.js:5)的函数,因此当我将导入更改为从“/client/js/js.cookie.min.js”导入Cookies时;现在它给出了一个错误,说明请求的模块“/client/js/js.cookie.min.js”没有提供名为“default”的导出@marleybowell这是另一个错误<代码>控制台日志(Cookies)。
    /client/js/js.cookie.min.js是否存在?console.log(Cookies)返回一些值该文件是什么?它是图书馆吗
    console.log(Cookies.get)
    :它是一个函数吗?console.log(Cookies.get)ƒ(e){返回C.call(C,e)}。我使用的是:所以我添加了事件侦听器。从“/client/js/js.cookie.min.js”导入*作为cookie;给出一个错误,说明login.js:5 Uncaught TypeError:Cookies.get不是HTMLDocument.resetLoginForm(login.js:5)的函数,因此当我将导入更改为从“/client/js/js.cookie.min.js”导入Cookies时;现在它给出了一个错误,说明请求的模块“/client/js/js.cookie.min.js”没有提供名为“default”的导出@marleybowell这是另一个错误<代码>控制台日志(Cookies)
    /client/js/js.cookie.min.js是否存在?console.log(Cookies)返回一些值该文件是什么?它是图书馆吗
    console.log(Cookies.get)
    :它是一个函数吗?console.log(Cookies.get)ƒ(e){返回C.call(C,e)}。我使用的是:
    import
    语句是否在没有定义
    type=“module”
    的情况下工作?导入
    语句是否在没有定义
    type=“module”
    的情况下工作?