多个 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")
或者什么?
我完全迷路了!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试像这样的更通用的选择器...
我不知道
div
和input
之间的关系,所以我无法假设选择器是什么,但是如果您发布关系或解释它,我们可以帮助您编写更准确的选择器。值得注意的是,如果您在 DOM 加载后将
ImageButton
动态添加到页面而不是在服务器端,那么您可能需要使用live
用于附加事件的方法...You could try a more generic selector like this...
I don't know the relationship between the
div
and theinput
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
ImageButton
s to the page after the DOM has loaded and not on the server side then you would likely want to use thelive
method for attaching events...只需将名为
class
的属性添加到您想要具有此效果制作器功能的ImageButtons
中,并为其指定一个名称,例如 effectMaker。然后调用相同的函数,但将选择器更改为使用
.
选择器后跟 stringValue,您可以引用具有以该 stringValue< 值表示的类的每个元素/em>。Simply add an attribute named
class
to theImageButtons
you want to have this effect maker function, and value it with a name, for example effectMaker. Then call the same function, but change the selector toWith the
.
selector followed by a stringValue, you reference every element that has a class valued with that stringValue.有人说委托功能比实时功能更好:
http://test.kingdesk.com/jquery /bind_live_delegate.php
Some say the delegate function is better than the live function:
http://test.kingdesk.com/jquery/bind_live_delegate.php
我不知道这是否适合您,但我所做的是:
我为我的按钮控件提供一个唯一的类来查找它,并批量解析整个列表视图。我不确定是否有一个或多个 div,但如果 div 位于 listview 行中,您还可以使用父项的组合并 find 也从 ListView 行中获取该 div。
这也将范围限制在 ListVIew 内;选择器不必解析整个页面来查找图像按钮,只需在列表中即可。
HTH。
I don't know if this will work for you, but what I've done is this:
I give my button control a unique class to find it with, and parse the entire list view in bulk. I'm not sure if there is one or many divs, but if the div is in the listview row, you can also use a combination of parents and find to grab that from the ListView row too.
This also keeps the scoping to within the ListVIew; the selector doesn't have to parse the entire page to find the image buttons, only within the list.
HTH.
这会将effect()应用于“theDiv”容器中“image”类型的每个输入:
或者,这会将其应用于每个输入类型图像点击上的“theDiv”:
不确定您要执行哪一个。
This will apply effect() on every input of type 'image' within the 'theDiv' container:
Or, this will apply it to 'theDiv' on every input type image click:
Not sure which one you're trying to do.