当前位置:网站首页>Location object
Location object
2022-06-24 18:35:00 【Brother Mengfan】
Catalog
1、 What is? location object

Example :
<form><input type="text" name="account" placeholder=" account number ">
<input type="password" name="pwd" placeholder=" password ">
<input type="submit" value=" Submit "> </form>
<script>
console.log(location);
console.log(location.protocol); // agreement
console.log(location.host);
console.log(location.hostname + ', ' + location.port);
console.log(location.href);
console.log(location.search);
</script>2、location attribute

Example : Save the request parameters in the object . Such as : hold user=xaoupeng&pwd=123456 Save to an object .
<form>
<input type="text" name="account" placeholder=" account number " value="xaoupeng">
<input type="password" name="pwd" placeholder=" password " value="123">
<input type="text" name="code" placeholder=" Verification Code " value="abc1">
<input type="submit" value=" Submit ">
</form>
<script>
// demand : Save the request parameters in the object . Such as : hold user=xaoupeng&pwd=123 Save to an object .
function getSearchString() {
// 1. adopt location Of search Property to get the parameter list of the request
// '?account=xaoupeng&pwd=123'
var queryString = location.search;
// 1.1 Determine whether the request parameters exist
queryString = queryString.length > 0 ? queryString : '';
// 2. Remove the... Before the string ? Number
// 'account=xaoupeng&pwd=123'
queryString = queryString.substr(1);
// console.log(queryString);
// 3. Cut multiple parameters
// ['account=xaoupeng', 'pwd=123']
var obj = {};
if (queryString.indexOf('&') !== -1) {
var parameters = queryString.split('&')
// 4. Traversal array , Then the parameter name and parameter value are segmented , And assign it to the object .
var items = null;
for (var i = 0; i < parameters.length; i++) {
//console.log(parameters[i]);
items = parameters[i].split('=')
//console.log(items);
obj[items[0]] = items[1]
}
}
console.log(obj);
return obj;
}
var result = getSearchString();
console.log(result);
</script>3、location Method
In addition to the above properties ,location The following methods are also provided in .

Method use example :
// location.href = 'https://www.baidu.com/'
location.assign('https://www.baidu.com');
// location.replace('a.html');
// location.reload();边栏推荐
- About whether arm's large and small end mode is related to CPU or compiler
- 腾讯云荣获“可信云技术最佳实践-虚拟化”
- SAP license: SAP s/4 Hana module function introduction
- About pyqt5 to realize paging function (one window implements different interfaces)
- Restful design method
- Nine practical guidelines for improving responsive design testing
- Two micro service interviews where small companies suffer losses
- 解决执行MapReduce程序控制台没有日志信息WARN Please initialize the log4j system properly
- Mariana Trench, Facebook's open source code analysis tool
- Three layer switching experiment
猜你喜欢

696. count binary substring

Leetcode weekly buckle 281
![717.1-bit and 2-bit characters [sliding window]](/img/61/449566d2a8efbd403ae0361f839683.jpg)
717.1-bit and 2-bit characters [sliding window]
congratulate! The first dragon lizard community annual outstanding contribution award is announced. Check it now
Paper sharing | self supervised learning paper jointly released by Yann Lecun and read by engineers

Exception: Gradle task assembleDebug failed with exit code 1

Three layer switching experiment

Business leaders compete for CIO roles

Complete Guide to web application penetration testing

Overall planning and construction method of digital transformation
随机推荐
Is there a security risk in opening an account online? What to do if the business department opening an account nearby is far away from home. Is there any capital requirement for opening an account?
Paper sharing | self supervised learning paper jointly released by Yann Lecun and read by engineers
Number of occurrences of numbers in the array (medium difficulty)
Business leaders compete for CIO roles
Ten excellent business process automation tools for small businesses
What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
如何在 R 中创建线性模型预测区间 并可视化
The mixed calculation of rpx and PX in JS by the uniapp applet
Three years of bug free, tips for improving code quality
congratulate! The first dragon lizard community annual outstanding contribution award is announced. Check it now
腾讯云TCS:面向应用的一站式PaaS 平台
Usage of typedef enum (enumeration)
EasyNVR使用Onvif探测设备失败,显示“无数据”是什么原因?
Software testing methods: a short guide to quality assurance (QA) models
Data driven decision making: Decision intelligence and design thinking
Selection (032) - what is the output of the following code?
Network security database penetration of secondary vocational group in 2022
Leetcode daily question solution: 717 1-bit and 2-bit characters - reverse order
Skills of writing test cases efficiently
Regression testing strategy for comprehensive quality assurance system