我相信 jQuery 的 :nth-child 选择器在 GreaseMonkey 0.8 中不起作用。 (底部是一个快速 GM 脚本来测试这一点。) 为什么是这样? 这是在 GreaseMonkey 中工作的已知限制吗? 谁能推荐一种解决这个问题的方法吗?
此外,为什么一些(绝对不是全部)jQuery 查询在 GreaseMonkey 中运行慢得多,我现在没有快速基准测试,但是我在构建 a pretty complex GM script that relied heavily in GM 时经常注意到它。我会在 GM 外部的 Firebug 中运行我的代码,事情会很快,而在 GM 内部,浏览器就会崩溃。我知道这很模糊,但我想知道 GM 或 jQuery 中是否存在一些广泛的架构原因,为什么会出现这种情况。
谢谢!
// ==UserScript==
// @name Test of nth-child
// @namespace http://elzr.com
// @description nth-child doesn't work in jQuery within GreaseMonkey
// @include http://en.wikipedia.org/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
// @author Eliazar Parra elzr.com
// ==/UserScript==
//
// For detailed info and screenshots see http://elzr.com/posts/wikipedia-backbars
$(document).ready(function() {
console.log($('a:nth-child(1)').length)
});
最佳答案
这可能与 GreaseMonkey 使用 XPCNativeWrapper 的方式有关为了安全。它们肯定会增加开销,并且可能会与 JQuery 产生冲突。
关于javascript - 为什么 jQuery 'nth-child' 选择器在 GreaseMonkey (0.8) 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/988823/