Replace http:// in anchor portion of links using J

2019-08-28 02:22发布

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://","");

2条回答
2楼-- · 2019-08-28 02:34

Just for the record, the jQuery-less version:

var links = document.links;
for(var i = links.length; i--; ) {
    with(links[i]) {
        if(/(^|\s)linked(\s|$)/.test(className)) {
            firstChild.nodeValue =
                firstChild.nodeValue.replace(/^http:\/\//, '');
        }
    }
}
查看更多
虎瘦雄心在
3楼-- · 2019-08-28 02:44

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...

查看更多
登录 后发表回答