用js或php按一定规律去替换链接地址

<html>
<body>
    <div class="top">
        <a class="zzz" href="http://www.abc.com/1.html">aaaa</a>
        <a class="xxx" href="http://www.abc.com/2.html">bbbb</a>
        <a class="ccc" href="http://www.abc.com/3.html">cccc</a>
    </div>
    <div class="content">
        <a class="ppp" href="http://www.abc.com/4.html">dddd</a>
        <a class="mmm" href="http://www.abc.com/5.html">eeee</a>
        <a class="kkk" href="http://www.abc.com/6.html">ffff</a>
    </div>
    <div class="qw-list">
        <a class="ft-item" href="http://www.abc.com/7.html">gggg</a>
        <a class="ft-item" href="http://www.abc.com/8.html">hhhh</a>
        <a class="ft-item" href="http://www.abc.com/9.html">iiii</a>
    </div>
</body>
</html>

要求说明:链接中的主域名abc.com是统一的,要求按照主域名是abc.com,并且类class="ft-item"一样的所有标签中的href网站替换为http://www.opq.com,其他不同类名的a标签href链接不变。最好是用js实现,或者是php。

阅读 2.1k
1 个回答

$('.ft-item').each(function(){
$(this).attr('href','http://www.opq.com/'+$(this).attr('href').split('/').pop());
})
如果没有其他特殊情况

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题