如何从datalist javascript或jquery获取点击图像的索引 [英] How to get index of clicked image from datalist either javascript or jquery
本文介绍了如何从datalist javascript或jquery获取点击图像的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
Hello,
<asp:DataList RepeatColumns="3" ID="repdetails" runat="server">
<ItemTemplate>
<table><tr><td style="border:1px solid #bfbfbf; width:50px;">
<asp:ImageButton ID="imgbtnid" runat="server" Width="40"
OnClientClick="return imagepopup(this.src);" Height="40" ImageUrl='<%# Eval("ivtf_docs_id", "../Imagenew.ashx?styleid={0}")%>'/>
</td></tr></table>
</ItemTemplate>
</asp:DataList>
当页面显示在浏览器上时,我有DataList中的图像列表。现在我需要从DataList获取点击图像的索引。
如果我点击第一张图片,它应该得到索引0,如果它是第二张图像,索引应该是1等等。
When the page shows on browser, I have list of images in DataList. Now I need to get index of clicked image from DataList.
if I click first image, it should get index 0 , if it is second image, index should be 1 and etc..
function imagepopup(thmsubimg) {
// here how to get index of clicked image from datalist.
return false;
}
需要帮助
Help needed
推荐答案
问题是你在DataList
中有Table。因此,对于DataList
的每一行,您实际上会获得许多表,然后是他们的行,然后在td
中,你有图像
。
所以,如果你点击图像并进入你写的功能,那么你需要实际计算主DataList
表中的图像数量,并根据它找到索引
特别的形象。那是因为你在一行中得到3列(td
)。因此,当您根据父td
索引进行计算时,您会发现前三个图像中的0,1,2
。然后下一行中的下一组图像
将与0,1,2相同。您将无法获得实际的索引
除非你计算。
请在浏览器上看到呈现的 HTML ,你会明白我在说什么关于。这样说,我建议你重新设计标记或者考虑适合正确结构的逻辑。
The problem is that you have Table inside theDataList
. So, for each row ofDataList
, you will actually get many Tables and then their rows and then inside thetd
, you have theImage
.
So, if you click on image and get into the function you have written, then you need to actually count the number of Images inside the mainDataList
Table and according to that find theindex
of that particular Image. That is because you are getting 3 columns (td
) inside one row. So, when you will calculate according to the parenttd
index, you will find 0, 1, 2 for the first threeimages
. Then next set ofimages
who are in the next row, will be the same like 0, 1, 2. You won't get the actualindex
unless you calculate.
Please see the rendered HTML on browser and you will be clarified what I am talking about. Saying that, I would suggest you to redesign the markup or think of the logic which will fit into the correct structure.
这篇关于如何从datalist javascript或jquery获取点击图像的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文