Chrome 扩展:Youtube 中的内容脚本 (jQuery) 无法正常工作
我有这个:
$(document).ready(function() {
$("button.yt-uix-expander-arrow").attr("id", "yt-uix-expander-arrow");
$("#yt-uix-expander-arrow").mouseover(function() {
alert("Hello");
});
});
注入 Youtube。使用右键单击>检查元素,
这是非常不寻常的,因为 #yt-uix-expander-arrow id 已经添加到按钮元素中。我在 Facebook 上测试了它,向类添加了一个 id,并在该 ID 上执行了 mouseover() 事件,它起作用了。
有什么想法吗?
I have this:
$(document).ready(function() {
$("button.yt-uix-expander-arrow").attr("id", "yt-uix-expander-arrow");
$("#yt-uix-expander-arrow").mouseover(function() {
alert("Hello");
});
});
injected into Youtube. Using right click > inspect element, the <button class="yt-uix-expander-arrow">
has a id="yt-uix-expander-arrow"
attribute successfully added to it. However the mouseover event does not trigger. However if I were to change $("#yt-uix-expander-arrow").mouseover()
to $(".yt-uix-expander-arrow").mouseover()
it works.
That's very unusual, because the #yt-uix-expander-arrow id has already been added to the button element. I tested it out on Facebook, adding a id to a class and doing a mouseover() event on the ID and it works.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能提供更多信息吗?你究竟想做什么(我的意思是不仅仅是显而易见的事情)?您能否以更容易测试的形式提供代码(即提供内容脚本或至少给出您尝试使用此代码的页面的 URL 以及内容脚本的摘要)?
您是否尝试将它们链接在一起?
我设置了我能做的最好的测试,你的代码工作得很好(我想,我再次不确定你到底想做什么)。如果没有更多背景,很难说哪里出了问题。
Can you provide more info? What exactly are you trying to do (I mean more than the obvious)? Can you provide code in a form that is more easily testable (i.e. provide the content script or at least give a url of a page you are trying to use this code on and a summary of the content script)?
Did you try just chaining them together?
I set up the best test I could and your code worked fine (I think, again I'm not sure EXACTLY what you're trying to do). It's hard to say what's wrong without more context.