【问题标题】:Executing a jQuery effect on demand. Is it possible?按需执行 jQuery 效果。是否可以?
【发布时间】:2011-03-12 15:58:27
【问题描述】:

我正在寻找 jQuery 的 Highlight 效果。这种效果确实是我想在我的网页中添加的效果。

通过查看源代码,我注意到效果会在用户点击div时重现。

$("div").click(function () {
      $(this).effect("highlight", {}, 3000);
});

在我的网页中,我有一个 ImageButton

<asp:ImageButton ID="btnFavorite" runat="server" ImageUrl="~/Images/Favorite.png"/>

当用户单击图像按钮时,我希望对div 执行突出显示效果。有可能吗?

更新:如果可能的话,我可以使用 ImageButton 的 "OnClientClick=" 之类的东西吗,因为 imagebutton 控件是动态添加到网页的?

【问题讨论】:

    标签: javascript jquery asp.net client-side jquery-events


    【解决方案1】:

    只需将click 处理程序绑定到您的图像按钮,如下所示:

    $("#btnFavorite").click(function() {
        // selector for element to highlight
        $("#theDiv").effect("highlight", {}, 3000);
    });
    

    更新:如果控件是动态添加/替换的,您可以使用.live 确保事件处理程序保持连接:

    $("#btnFavorite").live("click", function() {
        // selector for element to highlight
        $("#theDiv").effect("highlight", {}, 3000);
    });
    

    【讨论】:

    • 一些附加说明:asp.net 更改了 id 以使其唯一(除非您将 ClientIdMode 设置为静态),他可能需要 。我认为不需要 live,他可能是指动态服务器端(除非他使用 asp:updatepanel)
    猜你喜欢
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    相关资源
    最近更新 更多