我需要从网址中删除大小,即图像路径的分辨率。举几个例子:
http://raudevlocal.com/wp/wp-content/uploads/2017/05/0000362_chocolate-layer-cake-1024x682.jpeg
我需要删除-1024x682
http://raudevlocal.com/wp/wp-content/uploads/2017/05/rohit-300x118.jpg
需要删除-300x118
答案 0 :(得分:0)
使用正则表达式
$(document).ready(function(){
window.location.href = window.location.href.replace(/(-\d{2-6}x\d{2-6})/g,'');
});
答案 1 :(得分:0)
str = "http://raudevlocal.com/wp/wp-content/uploads/2017/05/0000362_chocolate-layer-cake-1024x682.jpeg";
str.replace(/-(\d+x\d+)/, "");
output will be
http://raudevlocal.com/wp/wp-content/uploads/2017/05/0000362_chocolate-layer-cake.jpeg
答案 2 :(得分:-1)
您可以使用replace
功能
window.location.href.replace('-1024x682', '');
如果您想使用新的网址作为当前网址,请尝试
window.location.href = window.location.href.replace('-1024x682', '');
答案 3 :(得分:-1)
使用正则表达式
var string = "http://raudevlocal.com/wp/wp-content/uploads/2017/05/0000362_chocolate-layer-cake-1024x682.jpeg";
console.log(string.replace(/-\d+x\d+/g,''));
window.loaction.href= window.location.href.replace(/-\d+x\d+/g,'');