NEW_URL:
<td class="posts column-posts"><a href="edit.php?tshowcase-categories=ops&post_type=tshowcase">2</a></td>
OLD_URL:
<span class="view"><a href="https://blog.company.com/team/tshowcase-categories/ops/">View</a></span>
我想用new_url替换旧网址。
var new_url = $("td.column-posts").find("a").attr('href');
$("span.view").find("a").attr('href',new_url)
我无法获得new_url的价值。
提供帮助。感谢
这是New_url的完整结构:
<tbody id="the-list" data-wp-lists="list:tag">
<tr id="tag-7" class="alternate">
<td class="posts column-posts"><a href="edit.php?tshowcase-categories=ops&post_type=tshowcase">1</a></td>
</tr>
</tbody>
答案 0 :(得分:0)
您可以这样做,只需为链接创建ID:
$('#2').attr('href', $('#1').attr('href'));
答案 1 :(得分:0)
在表标记
中包含 tbody<table>
<tbody id="the-list" data-wp-lists="list:tag">
<tr id="tag-7" class="alternate">
<td class="posts column-posts"><a href="edit.php?tshowcase-categories=ops&post_type=tshowcase">1</a>
</td>
</tr>
</tbody>
</table>
答案 2 :(得分:-1)
如果只有一个td
的课程为column-posts
var new_url = $("td.column-posts a").attr('href');
$("span.view a").attr('href',new_url)
如果有多个.column-posts
td,那么您必须在each
中写一下
$("td.column-posts a").each(function(){
$("span.view a").attr('href',new_url) //you have to map each span to each a
})