大家好,我是初学者 CTF 玩家,我和 javascript 有同样的湖,我面临以下问题
我不明白下面一行的意图是什么
location.search.match(/e=(.*)/)[1]))
这是完整的代码
if(location.search) {
var div = document.currentScript.parentNode.appendChild(document.createElement('div'));
div.className = 'alert alert-danger';
div.role = 'alert';
div.appendChild(document.createTextNode(unescape(location.search.match(/e=(.*)/)[1])));
}
你能帮我理解一下吗
最佳答案
location.search
基本上给你当前 URL 的查询字符串部分和 match
已用于使用正则表达式从查询字符串中提取 e
参数值。
举个例子,如果当前的 URL 是这样的
https://www.example.com/?e=someone@example.com
然后 location.search.match(/e=(.*)/)[1]
会给你 'someone@example.com'。
其余代码主要是创建一个 div 元素并将提取的文本设置为它的子元素,最后将该 div 添加为当前运行脚本标签的父节点的子元素。
关于javascript - javascript 中的 location.search.match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44601229/