【问题标题】:Javascript const arrow function [duplicate]Javascript const箭头函数[重复]
【发布时间】:2021-03-29 18:59:15
【问题描述】:

我知道这是一个愚蠢的问题,但我有点困惑,试图在互联网上查找但找不到任何东西......

在 JS (ES6) 中,我将箭头函数声明为 const,如何在页面加载时调用它?

es.

const bigBla = async () => { bla bla };

试过像onload="bigBla()"这样的smt但不起作用,还尝试在JS文件末尾调用它但在HTML文件中不起作用(需要更改span元素/src的innerHTML一个iframe,数据来自http请求),而如果我声明函数bigBla(){...}并使用onload="bigBla()"我没有问题。帮帮我:(

【问题讨论】:

  • consts 不会成为自动全局变量,因此 onload 找不到它。我推荐document.addEventListener('DOMContentLoaded', bigBla)

标签: javascript html constants arrow-functions


【解决方案1】:

在您的 javascript 文件中尝试 window.onload 函数。

window.onload = function() {
  bigBla();
};

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 2020-11-08
    • 2020-03-07
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 2018-11-10
    相关资源
    最近更新 更多