如何在Java脚本中读取asp.net中的行

How to read the row in asp.net in Java script

本文关键字:asp net 读取 Java 脚本      更新时间:2023-09-26

在下面的代码中,如果我点击第二列i wan读取第一列中的数据,那么第二列上就会出现一个图像。

假设我有10行,如果用户点击5行图标,那么我想阅读与第5行相关的所有细节。

    <table class="tableStyle" id="Table1">
        <thead>
              <tr>
                  <th id="Th1" style="background: none repeat-x scroll center top #027DBA;border-left: 1px solid #525252;width:15px;font-weight:bold">
                      <div>Request ID</div>
                  </th>
                  <th id="Th2" style="background: none repeat-x scroll center top #027DBA;border-left: 1px solid #525252;width:15px;font-weight:bold">Request Name
                  </th>
              </tr>
        </thead>
    <%
        for (int i = 0; i < ViewData.Model.Details.Count; i++)
        {
            //String id = i.ToString();
     %>
               <tr>
                   <td headers="Th1" style="background-color:#EFF3FB;border: 1px solid #C1C1C1;color: #000000; text-align:center"><%= ViewData.Model.Details.ElementAt(i).ID%>
                   </td>
                   <td headers="Th2" style="background-color:#EFF3FB;border: 1px solid #C1C1C1;color: #000000; text-align:center">
                        <a href="#"><img style="border:0;" src="/Content/Images/Icon.png" alt="Name" width="20" height="20" /></a>
                   </td>
               </tr>
        <%} 
    %>
</table>

使用jQuery,您可以在锚点标记上附加一个点击处理程序,并通过导航到其父级的上一个同级来定位数据。。。

$("a").on("click", function (e) {
    var data = $(this).parent().prev().text();
    alert(data);
    e.preventDefault();
});

JsFiddle