当前位置:网站首页>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();边栏推荐
- [can you really use es] Introduction to es Basics (I)
- Why are more and more people studying for doctors? Isn't it more and more difficult to graduate a doctor?
- Exception: Gradle task assembleDebug failed with exit code 1
- Three layer switching experiment
- Six configuration management tools that administrators must know
- Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
- Knowledge points of 2022 system integration project management engineer examination: ITSS information technology service
- 130. surrounding area
- Eight digit
- Redis learning -- list of redis operations
猜你喜欢

13 skills necessary for a competent QA Manager

解决执行MapReduce程序控制台没有日志信息WARN Please initialize the log4j system properly

国家出手了!对知网启动网络安全审查

Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs

Huitongda officially landed at the Hong Kong Stock Exchange: the gross profit margin continued to decline, and the book value of several shareholders still suffered losses

High quality defect analysis: let yourself write fewer bugs

About pyqt5 to realize paging function (one window implements different interfaces)

Creating a new MySQL user in Amazon RDS environment - creating a new MySQL user in Amazon RDS environment

ASP. Net hosting uploading file message 500 error in IIS

Five skills of selecting embedded programming language
随机推荐
R language Quantitative Ecology redundancy analysis RDA analysis plant diversity species data visualization
How does the chief information security officer discuss network security with the enterprise board of directors
Creating a new MySQL user in Amazon RDS environment - creating a new MySQL user in Amazon RDS environment
Selection (033) - what is the output of the following code?
What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
Business leaders compete for CIO roles
On the principle of cloud streaming multi person interaction technology
EasyNVR使用Onvif探测设备失败,显示“无数据”是什么原因?
130. surrounding area
Ultimate Guide: comprehensive analysis of log analysis architecture of Enterprise Cloud native PAAS platform
国家出手了!对知网启动网络安全审查
Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed
On software requirement analysis
微服务系统设计——子服务项目构建
Six configuration management tools that administrators must know
360 digital released information security trends in January: 120000 fraud risks were captured and users were reminded 2.68 million times
(Video + graphics) introduction to machine learning series - Chapter 11 support vector machines
Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
How can an enterprise successfully complete cloud migration?