代码之家  ›  专栏  ›  技术社区  ›  graham.reeds

单击事件激发两次

  •  0
  • graham.reeds  · 技术社区  · 15 年前

    我不知道这是否与拉斐尔、色彩盒或jquery有关。这是我的相关代码:

    var image = paper.image(p.url_, tx, ty, img.width, img.height);
    image[0].style.cursor = "pointer";
    image.node.onclick = function() {
        $.colorbox({
            title: "Some Random Title",
            href: function() {
                $.post("test.php", { arg: p.id_ } );
            }
        });
    };      
    

    当你在Firebug控制台中点击时,帖子会被触发两次。如果它也是一个吉特,它也会被解雇两次。

    如果我从href函数改为直接调用test.php,那么只发出一个GET。

    为什么在使用jquery时click事件发出两次调用?

    更新 :在匿名函数中添加对alert的调用也会触发两次,因此我猜这与colorbox有关。

    更新2 :刚尝试将其连接到实际页面,Firebug会在两个get/post之外发出此错误消息。这证实了这是颜色框中的问题。同时,它也很难取得进展,因为尽管两个调用都是完整的颜色框,但它显示了它的悸动。

    c is undefined 
        (function(b,gb){var v="none",t="click"...c.settings=eb;b(c.init)})(jQuery,this)
    

    注意:这只附在第二个电话上,而不是第一个。

    1 回复  |  直到 15 年前
        1
  •  1
  •   chriscauley    15 年前

    对色彩盒不太熟悉,所以我想出去走走。我猜你想让colorbox的html使用文章的结果。我会把这根柱子放在彩盒外面。你有什么理由不使用 $(image.node).click() ?甚至 $(image).click() ?我可以这样做

    var image = paper.image(p.url_, tx, ty, img.width, img.height);
    image[0].style.cursor = "pointer";
    $(image.node).click(function() {
        var post_html = $.post("test.php", { arg: p.id_ } );
        $.colorbox({
            title: "Some Random Title",
            html: post_html
        });
    });
    

    这可能无法修复它,但它将告诉您问题是colorbox触发了两次href,还是单击被执行了两次。

    推荐文章