Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Javascript query string location.search ()

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains how to use the Javascript query string location.search (). Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use the Javascript query string location.search ().

The following table lists all the properties of the location object (note: the location prefix before each attribute is omitted).

The property name example shows that hash "# contents" returns hash in URL (the # sign is followed by zero or more characters), or an empty string if the URL does not contain a hash. Host "www.jxbh.cn:80" returns the server name and port number (if any) hostname "www.jxhb.cn" returns the server name without the port number "http://www.jxbh.cn"" returns the full URL of the currently loaded page. The toString () method of the location object also returns the value .pathname "/ NewsList/" returns the directory in URL and (or file name) port "8080" returns the specified port number in URL, if the URL does not contain a port number, this property returns the empty string protocol "http:" returns the protocol used by the page, usually http: or httpssearch "? id=5" returns the query string of URL. The string begins with a question mark.

Although most of the information about the location object can be accessed through the above properties, it accesses the query characters contained in the URL

The properties of the string are not convenient. Although location.search returns everything from the question mark to the end of the URL, there is no way to access each of these query string parameters one by one. You can create a function like this to parse the query string and then return an object that contains all the parameters:

Function getQueryStringArgs () {

/ / get the query string and remove the starting question mark

Var qs= (location.search.length > 0? Location.search.substring (1): "")

/ / objects that save data

Var args= ()

/ / get each item

Varltems=qs .split ("&")

Var item=null.

Name=null.

Value=null

/ / add each item to the args object one by one

For (var iTuno Bandi)

At this point, I believe you have a deeper understanding of "Javascript query string location.search () how to use", might as well to actual operation it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report