根据jQuery中的另一个链接更改url
Change url based onanother link in jQuery
我需要使用 jQuery 使第二个 url 与第一个 url 相同。请参阅下面的我的 html 代码。它是div
和a
的列表。
<div class="text-center">
<h5 class="category"><a href="url" rel="tag">No need to change this url</a> </h5>
<div class="tx-div small"></div>
<a href="url1"><p class="name">Url</p></a>
<span class="price">
<div class="add-to-cart-button">
<a href="url2" rel="nofollow" class="add_to_cart_button product_type_simple button alt-button small clearfix" target="_blank">Change this to url1 </a>
</div>
</div>
<div class="text-center">
<h5 class="category"><a href="url" rel="tag">No need to change this url</a> </h5>
<div class="tx-div small"></div>
<a href="url1"><p class="name">Url</p></a>
<span class="price">
<div class="add-to-cart-button">
<a href="url2" rel="nofollow" class="add_to_cart_button product_type_simple button alt-button small clearfix" target="_blank">Change this to url1 </a>
</div>
</div>
请帮忙
更新的代码:
$('.text-center').each(function(){
$('a:eq(2)', this).attr('href', $('a:eq(1)', this).attr('href'));
});
试试这个代码:
$('.fc').each(function(){
$('.sec', this).attr('href', $('.fic', this).attr('href'));
});
试试这段代码,这是工作示例尝试....
$(".text-center").find('.url1').each(function( i ) {
var url1 = $(this).attr('href');
$(this).parent().find('.url2').attr('href',url1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="text-center">
<h5 class="category"><a href="url" rel="tag">No need to change this url</a> </h5>
<div class="tx-div small"></div>
<a class="url1" href="url1"><p class="name">Url</p></a>
<span class="price">
<div class="add-to-cart-button">
<a href="url2" rel="nofollow" class="add_to_cart_button product_type_simple button alt-button small clearfix url2" target="_blank">Change this to url1 </a>
</div>
</span>
</div>
<div class="text-center">
<h5 class="category"><a href="url" rel="tag">No need to change this url</a> </h5>
<div class="tx-div small"></div>
<a class="url1" href="url11111"><p class="name">Url</p></a>
<span class="price">
<div class="add-to-cart-button">
<a href="url22222" rel="nofollow" class="add_to_cart_button product_type_simple button alt-button small clearfix url2" target="_blank">Change this to url1 </a>
</div>
</span>
</div>
相关文章:
- 将重定向URL链接添加到JS函数
- 我如何重新加载URL链接,在我点击提交按钮后它保持不变
- 如何摆脱AngularJS中的当前域URL链接
- Javascript:我如何自动打开链接中的url链接
- 如何在Javascript中用URL链接不同的幻灯片图像
- 获取javascript中的URL链接名称
- 用于浏览器检测和url链接的脚本
- 翻译一篇文章'上.单击'PHP中的事件,来自'window.open'到基本URL链接
- javascript替换url链接循环
- 带有JS点击相对路径的网页URL链接
- 使用javascript基于登录用户重定向URL链接
- 带有URL链接且无重复项的旋转横幅
- 有一些条形图不是高图表上的 url 链接
- 如何使用 css 元素从 java 添加 url 链接
- 如何通过 css 元素从 jquery 添加 url 链接
- 使用 JavaScript 动态显示 URL 链接
- 使用JS逻辑从自定义选项构建URL链接
- 使用URL链接加载弹出窗口
- 为文件夹[javascript]中的文件生成URL链接列表
- 将数据存储到URL链接中