document.onclick = function(){
alert(this); //HTMLDocument,this代表的是document
};
window.onload = function(){
//document.onclick = box; //因为box()函数被onclick绑定了,所以里面的this代表document
};
function box(){
alert(this); //HTMLDocument,代表是document
};
box(); //object Window ,如果是在全局范围调用box(),那么this代表window
function box(){
alert(arguments.length); //获取传参的输了
};
box();
window.onload = function(){
document.onkeydown = function(){
//如果是事件处理函数绑定的函数,浏览器会默认传递一个参数,
//这个参数就是event对象
//alert(arguments[0]); //MouseEvent,鼠标事件对象
alert(arguments[0]); //KeyboardEvent,键盘事件对象
};
} ;
window.onload = function(){
document.onmouseup = function(evt){
if(getButton(evt) == 0){
alert("左键");
}
if(getButton(evt) == 1){
alert("中键");
}
if(getButton(evt) == 2){
alert("右键");
}
};
};
//ps:window.event 这个属性IE是支持的,Chorme也是支持的
//ps:Chrome也是支持w3c的
//ps:如果说w3c和IE的都支持的话,那么以w3c为准
//跨浏览器鼠标按钮
function getButton(evt){
var e = evt || window.event;
if(evt){ //这个写前面
return e.button;
}
else if(window.event){
switch(e.button){
//兼容IE和W3C
case 1:{
return 0;
}
case 4:{
return 1;
}
case 2:{
return 2;
}
//兼容360右击返回0的问题
case 0:{
return 2;
}
}
}
window.onload = function(){
document.onclick = function(evt){
var e = evt || window.event; //可视区坐标
alert(e.clientX + document.documentElement.scrollTop + "," + e.clientY);
//Chrome要用document.body.scrollTop
};
};
window.onload = function(){
document.onclick = function(evt){
var e = evt || window.event;
alert(e.screenX + "," + e.screenY); //屏幕坐标
}
}
}
window.onload = function(){
document.onclick = function(evt){
alert(getKey(evt));
}
}
function getKey(evt){
var e = evt || window.event;
var keys = [];
if(e.shiftKey){
keys.push("shift");
}
if(e.ctrlKey){
keys.push("ctrl");
}
if(e.altKey){
keys.push("alt"); //单击 + alt 和360的快捷键有冲突
}
return keys;
}