多个jQuery选择器 [英] Multiple jquery Selectors

查看:153
本文介绍了多个jQuery选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢 karim79 ,我能够点击ImageButton并将jQuery高亮效果应用于其他div

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

现在我想将问题扩展如下.

我将ImageButtons动态地添加到网页中,并且我希望在每次点击ImageButton时在div上应用效果.

     <asp:ListView ID="ListView1" runat="server">
        <layouttemplate>
            <asp:PlaceHolder id="itemPlaceholder" runat="server" />
        </layouttemplate>
        <ItemTemplate> 
        <asp:ImageButton ID="btnFavorite" runat="server" ImageUrl="~/Images/Favorite.png"/>
        </ItemTemplate>
    </asp:ListView>

在这种情况下我该怎么办?通过使用列表视图的ItemDataBound并添加属性 像

btnFavorite.Attributes.Add("onmouseclick", "doSomething")还是什么?

我完全迷路了!

解决方案

您可以尝试使用更通用的选择器,例如

$("input[type='image']").click(function(){
    $(".. related div selector ..").effect("highlight", {}, 3000);
});

我不知道divinput之间的关系,所以我不能假设选择器是什么,但是如果您发布该关系或对其进行解释,我们可以帮助您编写更准确的选择器. /p>

值得注意的是,如果在DOM加载后而不是在服务器端将ImageButton动态添加到页面中,那么您可能希望使用

Thanks to karim79 i am able to click on the ImageButton and apply the Jquery highlight effect to a different div

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

Now i would like to extend the question as follows.

I add the ImageButtons to the webpage dynamically, and i would like to apply the effect on the div for every ImageButton click.

     <asp:ListView ID="ListView1" runat="server">
        <layouttemplate>
            <asp:PlaceHolder id="itemPlaceholder" runat="server" />
        </layouttemplate>
        <ItemTemplate> 
        <asp:ImageButton ID="btnFavorite" runat="server" ImageUrl="~/Images/Favorite.png"/>
        </ItemTemplate>
    </asp:ListView>

What should i do in that case? By using ItemDataBound of the listview and adding attributes like

btnFavorite.Attributes.Add("onmouseclick", "doSomething") or what?

I am totally lost!

解决方案

You could try a more generic selector like this...

$("input[type='image']").click(function(){
    $(".. related div selector ..").effect("highlight", {}, 3000);
});

I don't know the relationship between the div and the input so I can't assume what the selector is but if you post the relationship or explain it we can help you write a more accurate selector.

It should be worth noting that if you are dynamically added the ImageButtons to the page after the DOM has loaded and not on the server side then you would likely want to use the live method for attaching events...

$("input[type='image']").live('click', function(){
    $(".. related div selector ..").effect("highlight", {}, 3000);
});

这篇关于多个jQuery选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆