标准浏览器下鼠标左中右键返回值分别是0,1,2,但是IE8及以下版本浏览器返回的却是1,4,2,兼容代码如下

document.onmousedown = function(event){
	alert(getButton(event));
}
function getButton(event){
	evt = event || window.event;
	if(event){
		return event.button;
	}else{
	switch(evt.button){
		case 1:
			return 0;
		case 4:
			return 1;
		case 2:
			return 2;
		}
	}
}

由于event对象在IE8下是属于window对象的,所以只要判断是否存在event就能区分出IE是哪个版本下

相关文章:

  • 2022-12-23
  • 2021-10-23
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-08-22
猜你喜欢
  • 2021-04-19
  • 2021-08-18
  • 2022-02-07
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
  • 2021-11-02
相关资源
相似解决方案