[英]e = event || window.event; statement is not working properly in Firefox
I am new to Javascript and jQuery so i have very silly doubt please bear with me 我是Java和jQuery的新手,所以我很傻的怀疑,请多多包涵
$(document).click(function () {
alert("!");
var e = event || window.event;
alert("!");
});
if i click on any part of the webpage then i should get two alerts with "!" 如果我单击网页的任何部分,则应该收到两个带有“!”的警报。 as the text, it is working as expected in Chrome.
如文本所示,它在Chrome浏览器中按预期运行。 In Firefox it is alerting only once
在Firefox中,它仅警报一次
Since you use jQuery, all you need to do is: 由于您使用jQuery,因此您所需要做的就是:
$(document).click(function (event) {
});
jQuery handles the browser differences and always passes an event object to the handler. jQuery处理浏览器差异,并始终将事件对象传递给处理程序。
I recommend to read the jQuery tutorial about event handling . 我建议阅读有关事件处理的jQuery教程 。
There is no event
variable you are referring to. 您没有要引用的
event
变量。 The Event object is the argument to the handler function. 事件对象是处理程序函数的参数。 It should be
它应该是
$(document).click(function (event) {
alert("!");
var e = event || window.event;
alert("!");
});
try this.you are not passing event parameter to function 试试这个。您没有将事件参数传递给函数
$(document).click(function (event) {
alert("!");
var e = event || window.event;
alert("!");
});
You have an error "event is not defined" why dont you get the event this way: 您有一个错误“未定义事件”,为什么不这样获取事件:
$(document).click(function (event) {
alert("!");
var e = event || window.event;
alert("!");
});
The event
is obviously undefined. 该
event
显然是不确定的。 So that line of code is causing a stop. 因此,该行代码导致停止。 You need to send the event to the click function.
您需要将事件发送到点击功能。
$(document).click(function(event){
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.