Chrome扩展程序:Youtube中的内容脚本(jQuery)无法正常运行

时间:2010-04-04 02:55:08

标签: javascript google-chrome mouseover

我有这个:

$(document).ready(function() {
    $("button.yt-uix-expander-arrow").attr("id", "yt-uix-expander-arrow");
    $("#yt-uix-expander-arrow").mouseover(function() {
        alert("Hello");
    });
});

注入Youtube。使用右键单击&gt;检查元素,<button class="yt-uix-expander-arrow">已成功添加id="yt-uix-expander-arrow"属性。但是,鼠标悬停事件不会触发。但是,如果我要将$("#yt-uix-expander-arrow").mouseover()更改为$(".yt-uix-expander-arrow").mouseover()则可以。

这是非常不寻常的,因为#yt-uix-expander-arrow id已经添加到按钮元素中。我在Facebook上测试了它,在一个类中添加了一个id并在ID上执行了mouseover()事件并且它有效。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您能提供更多信息吗?你究竟想做什么(我的意思不仅仅是显而易见的)?您能否以更易于测试的形式提供代码(即提供内容脚本或至少提供您尝试使用此代码的页面的URL以及内容脚本的摘要)?

你试过把它们连在一起吗?

$("button.yt-uix-expander-arrow").attr("id", "yt-uix-expander-arrow").mouseover(
    function() {
        alert("Hello");
    }
 );

我设置了最好的测试,你的代码工作正常(我想,我再也不确定你要做什么)。没有更多的背景,很难说出了什么问题。

相关问题