为什么OS X上的FF在click事件处理程序中丢失了jQuery-UI? [英] Why is FF on OS X losing jQuery-UI in click event handler?

查看:171
本文介绍了为什么OS X上的FF在click事件处理程序中丢失了jQuery-UI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用jquery 1.7.1和jQUery-UI 1.8.18的网页中,如果在文档准备就绪时在警告框中输出$ .ui,我会得到[object Object]。但是,当使用Firefox,如果我在一个点击事件处理程序输出$ .ui,我得到'undefined'的结果。使用其他浏览器(IE,Chrome和Safari的最新版本),结果仍然是[对象对象]点击链接。



这是我的HTML页面:

 <!doctype html> 
< html>
< head>
< title>< / title>

< script src =Scripts / jquery-1.7.1.jstype =text / javascript>< / script>
< script src =Scripts / jquery-ui-1.8.18.jstype =text / javascript>< / script>

< script type =text / javascript>
$(document).ready(function(){

alert($。ui); // ALERT A

$(document).on(点击,.dialogLink,function(){
alert($。ui); // ALERT B
return false;
});
});
< / script>

< / head>
< body>
< a href =#class =dialogLink>点击我!< / a>
< / body>
< / html>

在这篇文章中,我简化了最简单的形式, =https://stackoverflow.com/questions/9883486/this-dialog-is-not-a-function> $(this).dialog不是一个函数。为了清楚起见,我创建了一个新帖子,因为真正的问题与原来的问题是不同的,现在已经指出了问题所在。

UPDATE :

如果我用 alert($); 取代我的提示,提示A:

 函数(选择器,上下文){
返回新的jQuery.fn.init(选择器,上下文, rootjQuery);
}

和这一个提示B:

 函数(a,b){
返回新的d.fn.init(a,b,g);



$ b $ p
$ b这对我来说是没有意义的,虽然我可能不够理解什么 $ 是...



更新2:



我只能在OS X上使用Firefox来重现这个问题。在运行Windows 7的Firefox上,一切都很好。

解决方案

我认为你必须在OSX上的Firefox安装中加入一个附件,具体来说,我认为它加载页面加载后的页面jQuery的压缩版本,这是一个奇怪的事情,但解释你看到的行为。你的 $ 函数的提示清楚的显示了它从一个未压缩版本( return new jQuery.fn.init(selector,context,rootjQuery); / code>)转换成压缩版本( return new d.fn.init(a,b,g); ),重新加载jQuery将替换 $ 与一个全新的版本,这意味着jQuery UI的增加将从它消失。例如,在页面加载符合症状后加载压缩的jQuery。


$ b 如果没有附加组件(或恶意软件,我想这样做),没有理由 $ 或者 $。ui 会被您发布的页面重新定义,现在我已经在Chrome 17,Firefox 11和Linux 11(Ubuntu 11.10)上的Opera 11以及Windows 7上的IE9,Firefox 5,Safari 5和Opera 11。它们都按预期工作。



我会禁用所有加载项,然后重试。如果还是这样,我会彻底清除机器上的Firefox并重新安装。


In a web page using jQUery 1.7.1 and jQUery-UI 1.8.18, if I output $.ui in an alert box when the document is ready, I get [object Object]. However when using Firefox, if I output $.ui in a click event handler, I get 'undefined' as result. With other browsers (latest versions of IE, Chrome and Safari), the result is still [object Object] when clicking on the link.

Here is my HTML Page:

<!doctype html>
<html>
<head>
    <title></title>

    <script src="Scripts/jquery-1.7.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.8.18.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {

            alert($.ui);    // ALERT A

            $(document).on("click", ".dialogLink", function () {
                alert($.ui);    // ALERT B
                return false;
            });
        });
    </script>

</head>
<body>
    <a href="#" class="dialogLink">Click me!</a>
</body>
</html>

In this post, I reduced to its simplest form another problem I was having described here: $(this).dialog is not a function. I created a new post for the sake of clarity, since the real question is different from the original one now that pin-pointed where the problem resided.

UPDATE:

IF I replace my alerts with simply alert($); I get this result for alert A:

function (selector, context) {
    return new jQuery.fn.init(selector, context, rootjQuery);
}

and this one for alert B:

function (a, b) {
    return new d.fn.init(a, b, g);
}

This does not make sense to me, although I may not be understanding well enough what $ is...

UPDATE 2:

I can only reproduce this problem using Firefox on OS X. On Firefox running on Windows 7, everything is fine.

解决方案

I think you must have an add-on in your Firefox installation on OSX which is mucking about with the page; specifically, I think it's loading a compressed version of jQuery into the page after page load, which is a strange thing to do but explains the behavior you're seeing. Your alert of the $ function clearly shows it changing from an uncompressed version (return new jQuery.fn.init(selector, context, rootjQuery);) into a compressed version (return new d.fn.init(a, b, g);), and re-loading jQuery would replace $ with a completely new version, which means jQuery UI's additions would be gone from it. E.g., something loading a compressed jQuery after page load fits the symptoms.

Absent an add-on (or malware, I suppose) doing that, there's no reason that $ or $.ui would get redefined with the page you posted, and I've now tried it on Chrome 17, Firefox 11, and Opera 11 on Linux (Ubuntu 11.10) as well as IE9, Firefox 5, Safari 5, and Opera 11 on Windows 7. They all work as expected.

I'd disable all add-ons and try again. If it still happens, I'd completely wipe Firefox from the machine and reinstall from scratch.

这篇关于为什么OS X上的FF在click事件处理程序中丢失了jQuery-UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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