<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.circle{
width: 0;
height: 0;
border: 20px solid;
border-radius: 5px;
}
</style>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
// function f(id) {
// return new Promise(function (resolve,reject) {
// setTimeout((function (id) {
// return function () {
// console.log("Promise"+id);
// resolve(id);
// }
// })(id),1000)
// })
// }
//
// var arr=[1,2,3,4];
//
// Promise.all(arr.map(value => f(value)))
// .then(function (id) {
// console.log(id)
// console.log("resloved:"+id);
// },function (id) {
// console.log("reject:"+id);
// })
// function currying(fn, ...rest1) {
// return function(...rest2) {
// return fn.apply(this, rest1.concat(rest2))
// }
// }
//
// function sayHello(name, age, fruit) {
// this.a='sb';
// console.log(`我叫 ${name},我 ${age} 岁了, 我喜欢吃 ${fruit}`);
// }
//
// const curryingShowMsg1 = currying(sayHello, '小明');
//
// var func = new curryingShowMsg1('16','红烧肉');
// console.log(func === sayHello.prototype);
// console.log(document.getElementById("myframe").contentWindow.document);
console.log(document.getElementById("test"))
$(function () {
console.log(1)
})
window.onload=function () {
console.log(2)
}
window.onload=function () {
console.log(3)
}
$(function () {
console.log(4)
})
$(document).ready(function () {
console.log(5)
})
$(function () {
console.log(6);
console.log(window.getComputedStyle(document.getElementById("test")).backgroundColor);
})
document.onreadystatechange=function () {
if(document.readyState=='complete'){
console.log(7)
}
}
$(function () {
console.log(8)
})
</script>
<link rel="stylesheet" href="./css/test.css">
</head>
<body>
<div class="circle" id="SomeElementYouWantToAnimate"></div>
<div id="test"></div>
</body>
</html>
输出结果:
结论:jquery的$(function(){})与$(document).ready(function(){})是完全相同的,且可以多次定义,按执行顺序依此执行,onload只能执行依此,且执行函数为最后一次赋值的函数。