const url = 'http://127.0.0.1:2020/casic-aop'.replace('http//', '')
时间: 2023-12-23 10:06:23 浏览: 35
这段代码中的字符串替换有误,应该是将 `http//` 替换成 `http://`,即将双斜杠改成单斜杠。可以使用以下代码进行修正:
```javascript
const url = 'http://127.0.0.1:2020/casic-aop'.replace('http//', 'http://');
```
这样就可以将字符串 `'http//'` 替换成 `'http://'`,得到正确的 URL 地址 `'http://127.0.0.1:2020/casic-aop'`。
相关问题
写js代码,把http://www.baidu.com/proxy=http://www.hao123.com,这个url中的http://www.baidu.com/proxy= 提取出来
可以使用正则表达式来提取:
```javascript
const url = 'http://www.baidu.com/proxy=http://www.hao123.com';
const pattern = /http:\/\/www\.baidu\.com\/proxy=/;
const extracted = url.match(pattern)[0];
console.log(extracted); // http://www.baidu.com/proxy=
```
使用正则表达式 `/http:\/\/www\.baidu\.com\/proxy=/` 匹配 `http://www.baidu.com/proxy=`,然后使用 `.match()` 方法提取出来。
VUE2获取请求地址http://sso.chac.de/ssologout?redirect_uri=http://10.10.24.80:8088/home中的参数
你可以使用以下代码来获取请求地址中的参数:
```javascript
// 获取 URL 中的参数
function getQueryString(name) {
const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
const r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
// 示例调用
const redirectUri = getQueryString("redirect_uri");
console.log(redirectUri); // http://10.10.24.80:8088/home
```
在上面的代码中,`getQueryString` 函数使用正则表达式来匹配 URL 中的参数,如果找到匹配的参数,则返回该参数的值。你可以将你要获取的参数名作为参数传递给该函数。在示例中,我们通过传递 "redirect_uri" 来获取请求地址中的 "redirect_uri" 参数,并将其赋值给变量 `redirectUri`。