dtjw6660 2016-10-14 06:09
浏览 59
已采纳

如何重写URL的某些部分?

I have some image thumb code like below on my website coming from third party website to my website

<div class="thumb"><img src="//www.abc.com/website/thumbs/461/beautifulimage/test1a.jpg" rel="//www.abc.com/website/thumbs/461/beautifulimage/test1a.jpg"></div>

I want to replace URL from

//www.abc.com/website/thumbs/461 

to

//www.abc.com/website/thumbs/800

So, How I can replace URL on page load so it'll load code something like below

<div class="thumb"><img src="//www.abc.com/website/thumbs/800/beautifulimage/test1a.jpg" rel="//www.abc.com/website/thumbs/800/beautifulimage/test1a.jpg"></div>

Is there any way where I can call URL like this?

  • 写回答

1条回答 默认 最新

  • dongsuo0517 2016-10-14 06:28
    关注

    I assume it is matter of changing 461 to 800 in Image thumbnail URL. This can be solved easily with jQuery. Just iterate over all the thumbnail images and replace /461/ with /800/.

    This has to be done after document is ready, and this is how you can do it.

    $(document).ready(function(e){
        $('.thumb img').each(function(index){
           var urlpath=$(this).attr('src');
           urlpath=urlpath.replace("/461/", "/800/");
           $(this).attr('src',urlpath);
        });
    });
    

    Demo: https://jsfiddle.net/

    We have used each() jQuery function iterate over all the thumbnail images and used attr() jQuery function for setting and getting the src of image element.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题