当前位置:网站首页>js实现页面跳转与参数获取加载
js实现页面跳转与参数获取加载
2022-07-27 02:49:00 【有勇气的牛排】
1 页面跳转
location.replace("/search?q=" + keyword);
2 获取请求详细信息
let url = window.location.href; //获取当前窗口的Url; 结果:http://127.0.0.1:8081/search?q=Python
let host = window.location.host;//获取当前窗口的主机名; 结果:127.0.0.1:8081
let port = window.location.port; //获取当前窗口的端口; 结果:8081
let pathname = window.location.pathname;//获取当前窗口的路径 ; 结果:/search
let URL = document.URL;//获取当前文档的Url;结果:http://127.0.0.1:8081/search?q=Python
let search1 = window.location.search;//获取参数;结果:?q=Python
let origin = window.location.origin;//获取来源地址;结果:http://127.0.0.1:8081
let protocol = window.location.protocol;//获取协议;结果:http:
console.log("-------------")
console.log(url)
console.log(host)
console.log(port)
console.log(pathname)
console.log(URL)
console.log(search1)
console.log(origin)
console.log(protocol)
2 获取携带参数
函数
//key(需要检索的键) url(传入的需要分割的url地址,例:?id=2&age=18)
function getSearchString(key, Url) {
var str = Url;
str = str.substring(1, str.length); // 获取URL中?之后的字符(去掉第一位的问号)
// 以&分隔字符串,获得类似name=xiaoli这样的元素数组
var arr = str.split("&");
var obj = new Object();
// 将每一个数组元素以=分隔并赋给obj对象
for (var i = 0; i < arr.length; i++) {
var tmp_arr = arr[i].split("=");
obj[decodeURIComponent(tmp_arr[0])] = decodeURIComponent(tmp_arr[1]);
}
return obj[key];
}
调用
let search = window.location.search;
let q = getSearchString('q', search); //结果:云原生
console.log(q)
$("#keyword").val(q)
参考地址:
https://blog.csdn.net/Neil_clip/article/details/120972562
边栏推荐
- PSINS工具箱中轨迹生成工具详细解析
- Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns
- C language force deduction question 43 string multiplication. Optimized vertical
- Redis(九) - Redis之分布式锁
- JS array de duplication (including simple array de duplication and object array de duplication)
- 第六周复习
- Abstract intelligent extraction [based on Bert technology]
- 面试题:String类中三种实例化对象的区别
- Threads and processes
- VR全景现在是不是刚需?看完你就明白了
猜你喜欢

jmeter接口测试(登录、注册)

零基础小白也能懂的 Redis 数据库,手把手教你易学易用!

Realization of regular hexagon map with two-dimensional array of unity

Chapter 4 决策树和随机森林

【愚公系列】2022年7月 Go教学课程 018-分支结构之switch

VR全景制作在家装行业是谈单利器?这是为什么呢?

科目三: 济南章丘三号线

PSINS工具箱中轨迹生成工具详细解析

Chapter 5 决策树和随机森林实践

Skywalking distributed system application performance monitoring tool - medium
随机推荐
【无标题】
The job created by flinksqlclient will disappear after the restart of Flink. Is there any way?
分享当下人生——一个高中毕业生在中央电视台的六星期实习经历
jmeter接口测试(登录、注册)
【OBS】circlebuf
Will this flinkcdc monitor all tables in the database? Or the designated table? I look at the background log. It monitors all tables. If it monitors
Chapter 4 决策树和随机森林
Article main content extraction software [based on NLP technology]
Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns
Alibaba cloud server domain name and port web page cannot access the problem record
PSINS工具箱中轨迹生成工具详细解析
Ming min investment Qiu Huiming: behind the long-term excellence and excess, the test is the team's investment and research ability and the integrity of strategy
The 100th of the commercial anti counterfeiting series - boring systems and management processes can really be thrown into the trash can - by the way, analyze a dozen useless unity game self-test proj
JS array de duplication (including simple array de duplication and object array de duplication)
There is no problem reading from flick CDC to mysql8 and mysql5. What should I do?
C. Cypher
Parallels Desktop启动虚拟机“操作失败”问题解决
Startup process and rescue mode
线上一个隐匿 Bug 的复盘
Bean Validation原理篇--07