我需要找到并替换所有匹配的链接,例如我正在寻找
.domainname.com/Home我想用.domainname.com/我只想删除部分链接替换它
$('a').each(function() {
var $this = $(this),
aHref = $this.attr('href'); //get the value of an attribute 'href'
$this.attr('href', aHref.replace('domainname.com/Home', 'domainname.com/')); //set the value of an attribute 'href'
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="rd-navbar-nav">
<li>
<a href="https://domainname.com/Home">
<span>Home</span>
</a>
</li>
<li>
<a href="https://domainname.com/about-us">
<span>About Us</span>
</a>
</li>
<li>
<a href="https://domainname.com/contact-us">
<span>Contact Us</span>
</a>
</li>
</ul>
相关分类