jquery/userscript is not defined?
jquery/userscript is not defined?
在chrome中,我的用户脚本导致错误
ReferenceError: jQuery is not defined
但是@require行包含jquery。至少我知道它与防油剂有关(铬不支持吗?(
如果我删除了一个函数调用的函数(它使$=jQuery(,我会得到错误$没有定义。在firefox/防油精中,它运行良好的
// ==UserScript==
// @name Detect Duplicate IDs
// @namespace jkbfvsdjkzsvfshefsdvh
// @description Alerts you when more than one ID is on a page
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @include *
// @version 1
// @grant
// ==/UserScript==
//using localhost in @include doesn't seem to work
if(location.hostname!='localhost')
return;
//Ignore above for console.
(function($){
$(function() {
var checkDupeIDs = function () {
var dupes = [];
var ids = [];
$('[id]').each(function(i,e){ids.push(e.id)});
var len = ids.length;
for(i=0; i<len; ++i) {
if(dupes.indexOf(ids[i])!=-1)
continue;
for(n=i+1; n<len; ++n) {
if (ids[n]==ids[i]) {
dupes.push(ids[n]);
break;
}
}
}
if (dupes.length!=0) {
for(i=0; i<dupes.length; ++i)
console.warn('Multiple IDs #' + dupes[i]);
alert(dupes.join(''n'));
}
}
var jHtml = $.html;
$.html = function () {
checkDupeIDs();
return jHtml.call(this, arguments);
}
checkDupeIDs();
})
})(jQuery);
开箱即用,Chrome并不很好地支持Greasemonkey脚本(过期表,过期页面(。例如,@require
指令不起作用。
要享受与Firefox Greasemonkey脚本几乎完全兼容,请安装Chrome的Tampermonkey扩展。你的剧本应该在坦帕蒙基工作。
另外,为了避免Firefox出现问题,请不要将@grant
留空。如果没有其他内容,请使用@grant GM_addStyle
。
检查两件最重要的事情:
- 您已将jQuery包含在项目中
- 在使用jQuery的任何其他js文件之前,您已经包含了jQuery文件
相关文章:
- reactRedux is not defined
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- jQuery is not defined - WordPress footer.php
- GAPI Is Not Defined
- Page_ClientValidate is not defined
- ReferenceError: $firebase is not defined
- ReferenceError: crimeID is not defined
- AngularJS: $scope is not defined?
- ajaxUrl is not defined
- WebView: Uncaught ReferenceError: Android is not defined
- ReferenceError SetInterval not defined
- ReferenceError: yes is not defined
- ReferenceError "not defined"
- Soundcloud API ReferenceError: $ is not defined (JavaScript)
- Angular: Compile is not defined
- nodeJS phantom ReferenceError: Promise is not defined
- observableArray is not defined
- Uncaught ReferenceError trapArea/Per is not defined
- ReferenceError: xmlhttp is not defined