gpt4 book ai didi

javascript - 如何获取表中 TR 中 TD 的大陆值?

转载 作者:行者123 更新时间:2023-12-02 14:37:33 25 4
gpt4 key购买 nike

我想获取我点击的td的值我有一张 table ,在这张 table 上我有很多 tr 和 td我想获取我选择的td的值

enter image description here

<table id="table" class="table" style="margin-right: auto; margin-left: auto" >
<thead>
<tr>
<th>Numero demande</th>
<th>Date prelevement</th>
<th>Um executante</th>
<th>Id preleveur</th>

</tr>
</thead>
<tbody>



@foreach(var dem in @Model)
{

<tr>
<td><a id="lienFicheDemande"> @dem.DPR</a></td>
<td>@dem.Dateprelevement </td>
<td>@dem.UM </td>
<td>@dem.PRELEVEUR.NOMCOMPLET </td>
<td id="iddem" hidden="hidden">@dem.DPR<</td>
</tr>
}

</tbody>
</table>
</body>
<script type="text/javascript" >



$(document).ready(function (e) {

$('#lienFicheDemande').click(function (e) {

alert($('#iddem')[0].innerHTML);


window.open("Appli/Home/FicheDemande?iddem=" + $('#iddem').value, "nom_popup", " menubar=no");

});
});

</script>

我想将 dem_dpr 的值传递到 JavaScript 中的链接

最佳答案

首先,您不能以这种方式使用 ID。每个文档它们必须是唯一的。使用类而不是 ID。然后,您可以使用 .closest('.iddem') 获取最接近您单击的链接的元素,并使用 .html().text( ) 来获取它的值(value)。

示例:

<table id="table" class="table" style="margin-right: auto; margin-left: auto" >
<thead>
<tr>
<th>Numero demande</th>
<th>Date prelevement</th>
<th>Um executante</th>
<th>Id preleveur</th>

</tr>
</thead>
<tbody>



@foreach(var dem in @Model)
{

<tr>
<td><a class="lienFicheDemande"> @dem.DPR</a></td>
<td>@dem.Dateprelevement </td>
<td>@dem.UM </td>
<td>@dem.PRELEVEUR.NOMCOMPLET </td>
<td class="iddem" hidden="hidden">@dem.DPR<</td>
</tr>
}

</tbody>
</table>
</body>
<script type="text/javascript" >



$(document).ready(function (e) {

$('.lienFicheDemande').click(function (e) {

alert($(this).closest('.iddem').html());


window.open("Appli/Home/FicheDemande?iddem=" + $(this).closest('.iddem').html(), "nom_popup", " menubar=no");

});
});

</script>

关于javascript - 如何获取表中 TR 中 TD 的大陆值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37318417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com