Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在我的JavaScript ajax响应中用d://替换.././?_Javascript_Regex_String - Fatal编程技术网

如何在我的JavaScript ajax响应中用d://替换.././?

如何在我的JavaScript ajax响应中用d://替换.././?,javascript,regex,string,Javascript,Regex,String,我想使用JavaScript将ajax响应中的。/../替换为D:// 实际上,我想在我的html中将具有相对路径的图像srcattr./../替换为绝对路径。尝试以下操作: str = '../../dsadsddad' var new_str = str.replace('../../', 'D:/') // new_str = "D:/dsadsddad" var image = document.getElementById("your_image_id"). image.src =

我想使用JavaScript将ajax响应中的
。/../
替换为
D://


实际上,我想在我的html中将具有相对路径的图像
src
attr./../替换为绝对路径。

尝试以下操作:

str = '../../dsadsddad'
var new_str = str.replace('../../', 'D:/')

// new_str = "D:/dsadsddad"
var image = document.getElementById("your_image_id").
image.src = image.getAttribute('src').replace('../../', 'D:/')
如果要在图像中更改
src
attrubute,请尝试以下操作:

var image = document.getElementById("your_image_id").
image.src = image.getAttribute('src').replace('../../', 'D:/')
试试这个:

str = '../../dsadsddad'
var new_str = str.replace('../../', 'D:/')

// new_str = "D:/dsadsddad"
var image = document.getElementById("your_image_id").
image.src = image.getAttribute('src').replace('../../', 'D:/')
如果要在图像中更改
src
attrubute,请尝试以下操作:

var image = document.getElementById("your_image_id").
image.src = image.getAttribute('src').replace('../../', 'D:/')

string.replace(“../../”,“d:/”)-不需要使用regexCan,您可以分享您已经尝试和取得的成果吗?str.replace(//..\//..”,“d:/”);实际上,我想在我的htmlregex
/\.\.\/\.\.\/\.\.\/\.\.\/.\.\/.\/.\.\/.\.\/.\/.\/.\.\/.\/.\/.\/.\/.\/.\/././././g
string.replace(“../../../”,“d:/”)-不需要regexCan,你可以分享你已经尝试和取得的成果吗;实际上,我想在我的htmlregex
/\.\.\/\.\.\/\.\.\/\.\.\//g