Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.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 关于window.location.href.replace的各种可能性_Javascript_Jquery - Fatal编程技术网

Javascript 关于window.location.href.replace的各种可能性

Javascript 关于window.location.href.replace的各种可能性,javascript,jquery,Javascript,Jquery,我有一个问题: window.location.href.replace 是否可以将其应用于一组2个或更多的单词 例如: window.location.href = window.location.href.replace("-standard", "-standard-upload"); 我需要将两个单词替换为另一个2,在示例中,我将1更改为另一个1。可能是您可以这样做: var a = window.location.href; a = a.replace("-standard", "

我有一个问题:

window.location.href.replace
是否可以将其应用于一组2个或更多的单词

例如:

window.location.href = window.location.href.replace("-standard", "-standard-upload");

我需要将两个单词替换为另一个2,在示例中,我将1更改为另一个1。

可能是您可以这样做:

var a = window.location.href;
a = a.replace("-standard", "-standard-upload");
a = a.replace("old", "new");
window.location.href = a;

作为一般示例…

window.location.href=window.location.href.replace(“-standard”,“-standard upload”);但我需要改变另外两个词:上传中的类别你没有正确解释这一点。请您再试一次解释,以便我能帮助您。示例:www.substellar.it/tiket/stardard/this-is-Example必须变成www.substellar.it/upload/stardard/other-words-changedDo您的意思是
“-standard”
在原始字符串中多次出现,还是您还想替换一个完全不同的单词?请显示输入的示例
href
和相应的所需输出。示例:www.substellar.it/tiket/stardard/this-is-example必须变为www.substellar.it/upload/stardard/other-words-changed with window.location.href.replace您可以链接
.replace()
,例如:
x=x.replace(“a”、“b”).替换(“c”、“d”)
。为什么最后一行需要
.replace()
?只需做一个作业
…href=a
str = window.location.href;
str.replace("this", "another").replace("is", "words").replace("example", "changed")