gpt4 book ai didi

javascript - 在 greasemonkey 中使用 jQuery 插件(即 tipsy)

转载 作者:行者123 更新时间:2023-11-29 09:59:31 25 4
gpt4 key购买 nike

我正在尝试(并且大部分成功)在我的 greasemonkey 脚本中使用 tipsy jQuery 插件。我正在使用 @require 元标记导入 jquery 和 tipsy js,它可以工作,但有一些我试图克服的警告。

作为纯 jQuery 对象访问元素失败,所以我不得不使用 DOM 函数来获取我的元素:

//this fails
$('#login').find('a:first').tipsy();

//while this succeeds
$(document.getElementById('login').getElementsByTagName('a')[0]).tipsy();

有人知道为什么吗?需要更多信息? TIA!

最佳答案

我认为这是因为在 Greasemonkey 内部,jQuery 具有与文档不同的默认上下文。试试这个:

$("#login", document).find('a:first').tipsy();

关于javascript - 在 greasemonkey 中使用 jQuery 插件(即 tipsy),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4367772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com