像这样的代码:
$(window.document).ready(function () {
window.alert('alert 1');
});
$(function () {
window.alert('alert 2');
});
$(function () {
window.alert('alert 3');
});Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo2</title>
<script src="jquery-3.1.1.js"></script>
<script src="demo2.js"></script>
</head>
<body>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
当我执行上面的代码时,页面的警报顺序有时是:警报1,警报2,警报3,有时是:警报1,警报3,警报2.任何人都可以告诉我为什么?