2016-03-04 75 views
0

我想在網站上添加一個「info div」。對於這一點,我通過Tampermonkey腳本中添加一些HTML代碼:Tampermonkey - 使用jQuery和jQuery UI的問題

// ==UserScript==  
// @name         New script  
// @namespace http://tampermonkey.net/  
// @version      1.1  
// @description  try to take over the world!  
// @author       You  
// @match        http://www.monsite.com/*  
// @grant        GM_getValue  
// @grant        GM_setValue  
// @grant        GM_listValues  
// @grant        GM_addStyle  
// @grant        GM_getResourceText  
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js 
// @require  https://code.jquery.com/ui/1.11.4/jquery-ui.min.js 
// ==/UserScript==  
/* jshint -W097 */  
'use strict';  

var html = "<div id='myDiv'>CONTENT</div>";  
$('body').append(html); 

$(function() { 
    $("#myDiv").draggable(); 
}); 

當我嘗試將其移動,我有一個控制檯錯誤:

Uncaught TypeError: n.style is not a function 

有關信息,我得到了同樣的問題,如果我想用 $ .slideToggle() ..

任何想法如何解決這個問題?

感謝

回答

0

我想試試這個:

$(function() { 
    var $html = $("<div id='myDiv'>CONTENT</div>"); 
    $html.draggable(); 
    $('body').append($html); 
}); 

同時檢查所有在網站上運行的腳本。他們可能會干擾你的代碼,反之亦然,如果他們已經在運行JQuery。

+0

有了這個,我得到了同樣的錯誤 '$ html.draggable();' –

+0

我看到該網站使用jQuery 1.7 ..可以這是問題的根源嗎? –