问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/9900989/why-is-ff-on-os-x-losing-jquery-ui-in-click-event-handler