[英]How to remove domain name from the src URL attribute in Jquery
I'm fetching img src attribute into a variable, while doing so I'm getting the complete url of the image, i want to remove domain name from the url 我正在将img src属性提取到变量中,同时这样做我正在获取图像的完整URL,我想从网址中删除域名
var imgurl = "http://nitseditor.dev/img/home/bg.jpg";
I want to have only img/home/bg.jpg
. 我想只有img/home/bg.jpg
。 How can I achieve it? 我怎样才能实现它?
Get substring by getting the index of third /
. 通过获得第三索引获取子/
。
var imgurl = "http://nitseditor.dev/img/home/bg.jpg"; console.log( imgurl.substr(imgurl.indexOf('/', 7) + 1) );
url = url.replace(/^.*\/\/[^\/]+/, '')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.