jquery加载不工作在Firefox [英] Jquery load not working in firefox

查看:117
本文介绍了jquery加载不工作在Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的网站上,我遇到了一个脚本问题。它在Safari,Opera和Chrome中运行正常,但在firefox中不起作用。

当你点击一个链接时,我尝试从内部加载div #contain链接到一个覆盖div,然后是不隐藏的。所有这一切都在我上面提到的浏览器工作正常,但它不会在Firefox中工作,点击功能只是打开链接(重新加载页面),因为它通常会做。



任何想法,为什么它不起作用在Firefox? (b)

$ $ $ $ $ $ $ $ $ $ $ $ $ $($)
var $ ov = $('。overlay'),
$ tp = $('#transparent'),
URL ='',
siteURL =http:// + top.location.host.toString(),
$ internal = $(a [href ^ ='+ siteURL +'],a [href ^ ='/'],a [href ^ = './'],a [href ^ ='.. /'],a [href ^ ='#']:not('。no')),
hash = window.location.hash,
$ el,$ allLinks = $(a);


$ tp.hide();
$ ov.hide();


$ tp.click(function(){

$ ov.empty();
$ tp.hide();
$ ov .hide();

));


if(hash){

$ ov.show();
$ tp.show();
hash = hash.substring(1);
URL = hash +#contain;

$ ov.load(URL) ;

};

$ internal.each(function(){

$(this).attr(href,#+ this.pathname); ();
$ b $)

$) b $ el = $(this);
URL = $ el.attr(href)。substring(1);
URL = URL +#contain,

$ ov.load(URL);

});
});


解决方案

我认为您在click功能中缺少preventDefault。这告诉jQuery / javascript不要按照默认的行动,在你的情况下,将链接指向HREF中的任何地方。



而不是

$ pre $ $ tp.click(function(){
$ ov.empty();
$ tp.hide();
$ ov.hide();
});

应该是

  $ tp.click(函数(e){
e.preventDefault;
$ ov.empty();
$ tp.hide();
$ ov.hide();
});


I have got a problem with a script on a website I am developing. It works fine in Safari, Opera and Chrome, but it doesn't work in firefox.

As you click a link, I try to load the div #contain from internal links to an overlay div, which then is unhidden. All this is working fine in the browsers I have mentioned above, but it wont work in firefox, the click function just opens the link (reloads the page) as it would normally do.

Any Ideas why it does not work in Firefox? Anything that I am missing?

$(document).ready(function(){


    var     $ov = $('.overlay'),
        $tp = $('#transparent'),
        URL = ' ',
        siteURL = "http://" + top.location.host.toString(),     
        $internal = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']:not('.no')"),      
        hash = window.location.hash,
        $el, $allLinks = $("a");


        $tp.hide();
        $ov.hide();


        $tp.click(function(){

            $ov.empty();
            $tp.hide();
            $ov.hide(); 

        });


        if (hash) {

            $ov.show();
            $tp.show();         
            hash = hash.substring(1);
            URL = hash + " #contain";

            $ov.load(URL);

            };

        $internal.each(function(){

            $(this).attr("href", "#" + this.pathname);

            }).click(function(){

                $tp.show();
                $ov.show();

                $el  = $(this);
                URL = $el.attr("href").substring(1);
                URL = URL + " #contain",

                $ov.load(URL);

            });
    });

解决方案

I think you are missing preventDefault in your click function. This tells jQuery/javascript to not follow the default action which in your case would be following wherever the link is pointing to in HREF.

Instead of

$tp.click(function(){
    $ov.empty();
    $tp.hide();
    $ov.hide();
}); 

It should be

$tp.click(function(e){
    e.preventDefault;
    $ov.empty();
    $tp.hide();
    $ov.hide();
});

这篇关于jquery加载不工作在Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆