问题
I am attempting to use Greasemonkey and jQuery 1.4.2. When I install the Greasemonkey script jQuery is definitely downloaded and appears in the scripts directory. However the below code doesn't append anything to elements with the class PAPAGETITLE. What am I doing wrong?
// ==UserScript==
// @name PS Timesheet
// @namespace http://www.steelebit.com/gmscripts
// @description Used to fix a terrible implementation
// @include https://intranet.site.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
// ==/UserScript==
// Append some text to the element with id #someText using the jQuery library.
$(".PAPAGETITLE").append(" more text.");
回答1:
Update:
As of Greasemonkey version 0.9.1, jQuery 1.5.1 seems to work fine in all of my scripts and tests so far.
Greasemonkey does not work with jQuery 1.4 without some hacking.
Use jQuery 1.3.2.
See: http://forum.jquery.com/topic/importing-jquery-1-4-1-into-greasemonkey-scripts-generates-an-error (and others).
回答2:
I've blogged about another possible solution here, which works with jQuery 1.4.*
来源:https://stackoverflow.com/questions/3207199/greasemonkey-and-jquery-1-4-2-not-working