Javascript 按需执行jQuery效果。可能吗?

Javascript 按需执行jQuery效果。可能吗?,javascript,jquery,asp.net,client-side,jquery-events,Javascript,Jquery,Asp.net,Client Side,Jquery Events,我在看jQuery的效果。这就是我想在我的网页中添加的效果 通过查看源代码,我注意到,只要用户点击div,效果就会重现 $("div").click(function () { $(this).effect("highlight", {}, 3000); }); 在我的网页中,我有一个ImageButton <asp:ImageButton ID="btnFavorite" runat="server&qu

我在看jQuery的效果。这就是我想在我的网页中添加的效果

通过查看源代码,我注意到,只要用户点击
div
,效果就会重现

$("div").click(function () {
      $(this).effect("highlight", {}, 3000);
});
在我的网页中,我有一个ImageButton

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

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

更新:如果可能,我是否可以使用ImageButton的
“OnClientClick=“
”,因为ImageButton控件是动态添加到网页的?

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

$("#btnFavorite").click(function() {
    // selector for element to highlight
    $("#theDiv").effect("highlight", {}, 3000);
});
更新:如果控件是动态添加/替换的,则可以使用以确保事件处理程序保持连接状态:

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

另外一些注意事项:asp.net更改ID使其唯一(除非您将ClientIdMode设置为静态),他可能需要。我认为不需要live,他可能是指动态服务器端(除非他使用asp:updatepanel)