简体   繁体   English

是否可以通过单击HREF链接在表中获取值?

[英]Is there a way to get the value inside the table by clicking an HREF Link?

I am reading a JSON file, accessed via Python. 我正在读取通过Python访问的JSON文件。 The values from JSON file will be then displayed on a table. 然后,JSON文件中的值将显示在表上。 Per row, I have a button. 每行都有一个按钮。 What I want is to see the value when I click the button. 我想要的是单击按钮时看到的值。

What algorithm I could use in such a way that i could store the ALL values so when I click the button, I can get its corresponding ROW value. 我可以使用哪种算法来存储所有值,因此当我单击按钮时,可以获得相应的ROW值。

Iteration of my JSON file below: 下面是我的JSON文件的迭代:

<tr>
    <td align="center">{{ entryIteration.sha1 }}</td>
    <td align="center">{{ entryIteration.requestedStatus }}</td>
    <td align="center">{{ entryIteration.detectionName }}</td>
    <td>{{ entryIteration.userRemarks }}</td>
    <td>
        <a href="#" class="btn btn-success btn-sm" data-toggle="modal" data-target="#modalApprove">Approve</a>
        <a href="#" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalReject">Reject</a>
        <a href="#" class="btn btn-default btn-sm">View</a>
    </td>
</tr>
{% endfor %}
$('.btn btn-default').click(function(){
    var tdtext1 = $(this).closest('tr').find('.tdclass1')
     var tdtext2 = $(this).closest('tr').find('.tdclass2')
})

Use .closest() to get the value of data in the row where the button is 使用.closest()获取按钮所在行中的数据值

Description: For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree. 说明:对于集合中的每个元素,通过测试元素本身并遍历DOM树中的其祖先,获得与选择器匹配的第一个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM