使用Jquery替换链接的锚部分中的http:// [英] Replace http:// in anchor portion of links using Jquery
本文介绍了使用Jquery替换链接的锚部分中的http://的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
页面上有以下几个链接:
< a class =linkedhref =http: /link1.com> http://link1.com</a>
< a class =linkedhref =http://link2.com> http://link2.com< ; / a>
如何删除每个链接中的第二个http://,
我试过这个无效:
$(document).ready(function(){
$('。linked')。html()。replace(http://,);
解决方案
如果你正在谈论锚标签中的可见文本
$。each($('。linked'),function()
{
var anchor = $ );
anchor.text(anchor.text()。replace(http:\ / \ /,''))
});
在结尾缺少');'...
on a page there a several links of:
<a class="linked" href="http://link1.com>http://link1.com</a> <a class="linked" href="http://link2.com>http://link2.com</a>
How would one remove the second http:// in each link so it can't be seen on the screen.
I've tried this to no avail:
$(document).ready(function() { $('.linked').html().replace("http://","");
解决方案If you are talking about the visible text in an anchor tag
$.each($('.linked'), function() { var anchor = $(this); anchor.text( anchor.text().replace("http:\/\/",'') ) });
Missing ');' at the end...
这篇关于使用Jquery替换链接的锚部分中的http://的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文