IE和FireFox中JS兼容之event .
发布日期:2021-07-23 08:50:51
浏览次数:112
分类:技术文章
本文共 1050 字,大约阅读时间需要 3 分钟。
转载于:
event对象
IE 中可以直接使用 event 对象,而 FF 中则不可以,解决方法之一如下:
var theEvent = window.event || arguments.callee.caller.arguments[0];第二种是将 event 作为参数来传递:
function xxx(e){var theEvent = window.event || e;}srcElement 和 target
在 IE 中 srcElement 表示产生事件的源,比如是哪个按钮触发的 onclick 事件,FF 中则是 target。
var theEvent = window.event || arguments.callee.caller.arguments[0];
var theObj=theEvent.target || theEvent.srcElement;例子:
document.onclick = function(e){
var theEvent = window.event || e; var theObj=theEvent.target || theEvent.srcElement;function clickAction(){
var theEvent = window.event || arguments.callee.caller.arguments[0]; var theObj=theEvent.target || theEvent.srcElement;// do something;
}function clickAction(e){
var theEvent = window.event || e; var theObj=theEvent.target || theEvent.srcElement;// do something;
}event.keyCode 和event.which
FF不支持window.event.keyCode,代替着是event.which
列子:
//在网页上面屏蔽tab键的代码
document.onkeydown = function (e){ var theEvent = window.event || e; var code = theEvent.keyCode || theEvent.which; if(code == 9){ return false; } }
转载地址:https://blog.csdn.net/namechenfl/article/details/84140366 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
很好
[***.229.124.182]2024年03月29日 03时12分30秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
资金流入流出预测-挑战Baseline-排名445 /122.17
2019-04-26
第四届工业大数据创新竞赛-注塑成型工艺的虚拟量测和调机优化-决赛排名22
2019-04-26
大数据时代的Serverless工作负载预测-排名80_0.313
2019-04-26
python爬虫爬取_腾讯位置大数据_人口迁徙图16年至今数据
2019-04-26
python爬虫爬取_高德地图_主要城市迁徙意愿排行榜_19年至今数据
2019-04-26
联通手机信令大数据的处理分析与可视化
2019-04-26
CNC机床刀具寿命预测
2019-04-26
Python遗传算法求解TSP旅行商问题——全国主要城市交通最短路径
2019-04-26
LeetCode题解(1114):多线程按序打印(Python)
2019-04-26
LeetCode题解(1122):数组的相对排序(Python)
2019-04-26
LeetCode题解(1128):等价多米诺骨牌对的数量(Python)
2019-04-26
LeetCode题解(1137):计算斐波那契数列(Python)
2019-04-26
LeetCode题解(1154):判断日期在一年中的第几天(Python)
2019-04-26
LeetCode题解(1160):判断可由指定字母拼写的所有单词总长(Python)
2019-04-26
LeetCode题解(1170):比较字符串最小字母的出现频次(Python)
2019-04-26
LeetCode题解(1175):质数排列(Python)
2019-04-26
LeetCode题解(1179):重新格式化部门表(SQL)
2021-06-29
LeetCode题解(1184):公交站间的距离(Python)
2021-06-29
LeetCode题解(1185):依据日期判断是星期几(Python)
2021-06-29
LeetCode题解(1422):分割字符串的最大得分(Python)
2021-06-29