有一個表由許多帶有列的表格行組成。從一個元素中獲取一個值並添加到每個href的末尾
我想從每個td的類名:routecode,我必須將該值添加到每個tr的最接近href的末尾。我會將此添加到路由代碼鏈接的值。
我寫了下面的代碼,但它不起作用,值不會添加到鏈接的結尾。
這裏是我的代碼:
$(".list").each(function(index, element) {
var routecode = $(this).closest("tr").find(".routecode").text()
var linkk = $(this).attr("href")
$(this).attr("href", linkk + routecode);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<html>
<head>
</head>
<body>
<table border="1">
<tr class=" odd">
<td class="routecode">TK26</td>
<td>
<a class="list" href="/reservation/route/info.bc?dmnid=2893&routecode=">Edit </a>
</td>
</tr>
<tr class=" odd">
<td class="routecode">tkeee</td>
<td>
<a class="list" href="/reservation/route/info.bc?dmnid=2893&routecode=">Edit </a>
</td>
</tr>
</table>
</body>
</html>
路線代碼被添加到鏈接的末尾。有什麼問題? –
其增加。只要檢查元素 –
他們是誰,請再次檢查您的代碼 –