function show() {
console.log(this);
alert("ready");
}
show();
console.log(this);
这两个this都指向window 那么在外面加上$(document).ready...
$(document).ready(function() {
function show() {
console.log(this);
alert("ready");
}
show();
console.log(this);
});
这两个this分别打印什么?为什么
第一个 this 指向 window , 第二个 this 指向 document。
第一个是因为 相当于 window.show() ,第二个是在 reday 里面的回调函数中。