javascript - 网页包。在窗口级别调用 Javascript 函数
问题描述
我正在打包我的 javascript
alert("Loaded out")
function showLoaded() {
alert("Loadedin")
}
试图调用从 html加载的函数
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="./bundle.js"></script>
</head>
<body>
<script>showLoaded()</script>
</body>
</html>
已加载由 alert 显示,但我似乎无法调用函数 showLoaded()。我在这里遗漏了一些明显的东西吗?
解决方案
您也可以通过这种方式公开您的函数:
alert("Loaded out");
function showLoaded() {
alert("Loadedin");
}
window.showLoaded = showLoaded;
推荐阅读
- css - 是否总是在新值之前应用新转换?
- encryption - 密码保护与 AES 加密
- r - 在 R 中选择多个非连续列时出错
- node.js - 事件.js:288。:无法读取 null 的属性“项目”
- r - HighcharteR:工具提示未显示正确的 x 轴值
- bluetooth - Raspberry PI BTLE 可以发现 Fitbit 和 Scale 设备,但无法配对
- asp.net-core - 如何使用目录名称中的句点从 Asp .Net Core 提供静态文件
- java - 当我运行 Maven 打包的 JAR 文件时出现 NoClassDefFoundError
- flutter - 如何在颤动的滚动视图中将容器或任何其他小部件固定在应用栏下方
- sql - 为什么会引发变异表错误?