如何通过项目的客户端ID在中继器的JavaScript [英] How to pass client id of Item in repeater to javascript
本文介绍了如何通过项目的客户端ID在中继器的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要的div客户端ID传递到JavaScript的一个中继器
I need to pass div client id to JavaScript of a repeater
我有一个中继器,我有onmouseover事件我想抓住div元素的客户端ID内3的div有什么办法,我可以通过div元素的确切客户端
I have 3 divs inside a repeater i have onmouseover event i want to grab client id of div element Is there any way i can pass exact client of div element
u能家伙帮我谢谢
推荐答案
这样的事情(如果我理解正确的你):
Something like this (if I understood you correctly):
标记:
<asp:Repeater id="myRepeater" OnItemDataBound="myRepeater_ItemDataBound" runat="server">
<ItemTemplate>
<div id="myDiv" runat="server">......</div>
</ItemTemplate>
</asp:Repeater>
code-背后:
Code-behind:
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HtmlGenericControl myDiv = e.Item.FindControl("myDiv") as HtmlGenericControl;
// you can just pass "this" instead of "myDiv.ClientID" and get the ID from the DOM element
myDiv.Attributes.Add("onmouseover", "doStuff('" + myDiv.ClientID + "');");
}
}
这篇关于如何通过项目的客户端ID在中继器的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文