【问题标题】:Get error just Importing library (via @require) in Tampermonkey在 Tampermonkey 中导入库(通过@require)时出错
【发布时间】:2019-08-31 05:45:03
【问题描述】:

我想在我的 Tampermonkey 脚本中导入 dragtable.js,但我收到此错误(jQuery 已经在我的网站中):

[错误] 错误:脚本“DragTable”执行失败!未定义是 不是函数(靠近'...$.widget...')错误(匿名函数) (userscript.html:2:186) ... ...

这是我的脚本:

// ==UserScript==
// @name         DragTable
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://localhost:9010/*
// @require https://rawgit.com/akottr/dragtable/master/jquery.dragtable.js

// @grant        none
// ==/UserScript==

我怎样才能在没有错误的情况下导入它?提示

【问题讨论】:

  • 看来你还需要导入jquery。
  • 我的网站已经有它了

标签: javascript tampermonkey


【解决方案1】:

请参阅dragtable's ReadMe,该库需要 jQueryjQuery UI

从列出的错误来看,jQuery UI 似乎不存在。

因此,您的脚本至少应该是:

// ==UserScript==
// @name        DragTable, getting started
// @match       http://localhost:9010/*
// @require     http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js
// @require     https://rawgit.com/akottr/dragtable/master/jquery.dragtable.js
// @grant        none
// ==/UserScript==


但是,请参阅this other Q&A for a more details about jQuery UI in a userscript

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    相关资源
    最近更新 更多