【发布时间】:2014-11-10 06:00:09
【问题描述】:
我在http://www.thefreedictionary.com/abnormally 网站上有下面的代码要由 Tampermonkey 在 chrome 中执行
我在页面中单独尝试了它,它可以工作,但不能通过 Tampermonkey 工作。
代码如下:
// ==UserScript==
// @name linkify span href
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match http://www.thefreedictionary.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js
// @copyright 2012+, You
// @grant GM_log
// ==/UserScript==
//alert("hello");
jQuery(document).ready (Greasemonkey_main);
function Greasemonkey_main ()
{
alert("hjello");
jQuery("span.hvr").each(function () { jQuery(this).wrap('<a href="/' + jQuery(this).text() + '" style="text-decoration:none;color:inherit" target="_blank"></a>')})
}
为了检查我也放了一个警报,警报有效,但不是 jquery 一行代码。
不知道为什么。请帮忙。
注意:
这一行代码是做什么的?
它只是将页面中的每个 span 标签都用一个锚标签包裹起来。
如何在该页面中试用该代码?
添加jQuery链接的脚本标签,然后从控制台执行那一行就可以了。
【问题讨论】:
-
你检查你是否进入了每个循环?用 console.log 什么的?
标签: javascript jquery tampermonkey