Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从元素中获取值并添加到每个href的末尾_Javascript_Jquery_Html - Fatal编程技术网

Javascript 从元素中获取值并添加到每个href的末尾

Javascript 从元素中获取值并添加到每个href的末尾,javascript,jquery,html,Javascript,Jquery,Html,有一个表由许多带列的表行组成 我会从每个td中获取一个值,该值的类名为:routecode,我必须将该值添加到每个tr的最近href的末尾。我会将该值添加到routecode链接的值中 我写了下面的代码,但它不工作,并且没有将值添加到链接的末尾 这是我的密码: $(“.list”)。每个(函数(索引、元素){ var routecode=$(this.closest(“tr”).find(“.routecode”).text() var linkk=$(this.attr(“href”) $(

有一个表由许多带列的表行组成

我会从每个td中获取一个值,该值的类名为:routecode,我必须将该值添加到每个tr的最近href的末尾。我会将该值添加到routecode链接的值中

我写了下面的代码,但它不工作,并且没有将值添加到链接的末尾

这是我的密码:

$(“.list”)。每个(函数(索引、元素){
var routecode=$(this.closest(“tr”).find(“.routecode”).text()
var linkk=$(this.attr(“href”)
$(this.attr(“href”,linkk+routecode);
});

TK26
特基
您可以尝试以下代码:

您缺少分号
行尾

此处演示:


$(文档).ready(函数(){
$(“.list”)。每个(函数(索引、元素){
var routecode=$(this.closest(“tr”).find(“.routecode”).text();
var linkk=$(this.attr(“href”);
$(this.attr(“href”,linkk+routecode);
});
});
TK26
特基
您可以尝试以下代码:

您缺少分号
行尾

此处演示:


$(文档).ready(函数(){
$(“.list”)。每个(函数(索引、元素){
var routecode=$(this.closest(“tr”).find(“.routecode”).text();
var linkk=$(this.attr(“href”);
$(this.attr(“href”,linkk+routecode);
});
});
TK26
特基

路线代码添加到链接的末尾。问题是什么?它补充道。只需检查元素。如果它们是,请再次检查您的代码。路线代码添加到链接的末尾。问题是什么?它补充道。只需检查元素。如果它们是,请再次检查您的代码。问题中是否没有附加
routecode
?问题中是否没有附加
routecode
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
   $(".list").each(function(index, element) {
    var routecode = $(this).closest("tr").find(".routecode").text();
    var linkk = $(this).attr("href");
    $(this).attr("href", linkk + routecode);
  });
});
</script>
</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>