gpt4 book ai didi

javascript - 使用 URL.Document 或 window.location.href 时大括号转换为十六进制

转载 作者:行者123 更新时间:2023-12-02 20:12:40 25 4
gpt4 key购买 nike

想要获取 document.URL,找到带有大括号的字符串,删除大括号,然后仅显示大括号内的字符串。但是,似乎 document.URL 或 window.location.href 将大括号转换为十六进制值(%7B 和 %7D),然后我无法与实际的 {string} 匹配。任何帮助将不胜感激。

  var txt = document.URL; // My URL is something like http://site.com/somepage&value0={string}
var re1='.*?'; // Non-greedy match on filler
var re2='(\\{.*?\\})'; // Curly Braces 1

var p = new RegExp(re1+re2,["i"]);
var m = p.exec(txt);

if (m != null)
{
var cbraces1=m[1];
document.write(cbraces1.replace("{","").replace("}",""));
}

最佳答案

使用decodeURI(document.URL)首先。

var txt = decodeURI(document.URL);

关于javascript - 使用 URL.Document 或 window.location.href 时大括号转换为十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6771422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com