Javascript 使用Firefox浏览时Jquery不工作
您好,我正在使用以下代码:Javascript 使用Firefox浏览时Jquery不工作,javascript,jquery,firefox,Javascript,Jquery,Firefox,您好,我正在使用以下代码: $("#cart").click(function () { if ($(event.target).closest('.content').length > 0) return false; $('#cart').load('index.php?route=module/cart #cart > *'); var e = window.event || e; $("#cart").toggleClass("active")
$("#cart").click(function () {
if ($(event.target).closest('.content').length > 0) return false;
$('#cart').load('index.php?route=module/cart #cart > *');
var e = window.event || e;
$("#cart").toggleClass("active");
e.stopPropagation();
$(document).click(function (e) {
$("#cart").removeClass("active");
$('#cart').live('mouseleave', function () {
// Code Here
});
});
});
它在Chrome上运行得很好,但在Firefox上测试时却不起作用。行不通的是:
if ($(event.target).closest('.content').length>0) return false;
为什么这在Chrome中有效而在Firefox中无效?您没有传递事件参数 像这样试试
$("#cart").click(function(event) {
// now put your code here
}
您忘记添加
事件
作为侦听器的参数
$("#cart").click(function (event) {
if ($(event.target).closest('.content').length > 0) return false;
$('#cart').load('index.php?route=module/cart #cart > *');
var e = window.event || e;
$("#cart").toggleClass("active");
e.stopPropagation();
$(document).click(function (e) {
$("#cart").removeClass("active");
$('#cart').live('mouseleave', function () {
// Code Here
});
});
});
firefox控制台中有错误吗?它给了我“ReferenceError:事件未定义”哦,这是一个非常简单的修复!我现在觉得自己很愚蠢,我想我忽略了它哈哈。我可以问一下为什么它在Chrome中工作吗?有
window.event
处理事件,但对于firefox,他不支持它。即使在严格模式下也不支持它。