首页 > 解决方案 > jquery url没有替换

问题描述

我有 jquery 正则表达式,它在顶部找到网址 URL 并将其替换为新的 URL,但是我编写的正则表达式更改了 URL,但正则表达式在末尾添加了 URL 中的其他额外内容。它添加3543463456546456得很好,而不是https://127.0.0.1/id=12345

<script>
 var urlTest = $(location).attr("href");
 var test1 = urlTest.replace(/https:\/\/127.0.0.1\/test1\/test2\/(12345)\/3543463456546456/g, "https://127.0.0.1/id=$1");
 $(".test").append(document.write(test1));
</script>

不知道为什么它拿起 3543463456546456

标签: javascripthtmljquery

解决方案


推荐阅读