我有这个非常简单的 html 文件。
<!doctype html>
<html>
<head>
</head>
<body>
<script>alert("hi");</script>
</body>
</html>
这通常在我的笔记本电脑上的 Firefox 和 Google Chrome 中运行良好。但是,当我在 iPhone 设备的 Safari 和 Android 设备的 Google Chrome 中运行它时,JavaScript 代码不会运行。也就是说,不会出现警报。这对我来说非常不寻常。在移动设备上运行时,我们需要更改 JavaScript 代码吗?我该怎么办?
最佳答案
(function(){
window.alert('hi')
})()
<html>
<head>
</head>
<body>
</body>
<script src="aJSfile.js"></script>
</html>
添加 window to alert 使其显示 window.alert('hi')
也可以看到大多数浏览器支持的核心窗口函数
https://developer.mozilla.org/en-US/docs/Web/API/Window/alert
关于移动网络浏览器中的 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33971803/