我有以下简单的 java 脚本代码,当我在 Microsoft Edge 中按“刷新”按钮时,该代码不会执行。刷新时这 3 个警报均不会执行。它与 Chrome 配合良好。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript">
jQuery(function() {
alert('jQuery');
});
function func() {
alert('func');
}
function load() {
alert('load');
}
window.onload = load();
func();
</script>
</head>
<body>
</body>
</html>
此代码可以放入 HTML 文件 (test.html) 中。
为什么会发生这种情况?谢谢。
最佳答案
也许使用window.addEventListener("load", load, false);
。有时,如果一件事不起作用,另一件事就会起作用。
关于javascript - Microsoft Edge 刷新按钮不执行 onLoad javascript 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41025731/