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 get url and url parameters by Jquery

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

Share

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

This article mainly introduces Jquery how to obtain url and url parameters, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

When passing parameters in the Get mode of a web page, we sometimes add Get request parameters to the back of the web page. At the front end of the page, we can use Jquery to obtain the parameter information in the Url address, through the segmentation of the URL address parameters, and finally encapsulate into a Jquery method to obtain the request parameters in the URL through the corresponding key value.

First introduce the Jquery.js file on the page, and then define a common function getUrlParam in the $(document) function. As follows:

(function ($) {

$. GetUrlParam=function (name) {

Var reg=new RegExp ("(^ | &)" + name + "= ([^ &] *) (& | $)")

Var r=_window.location.search.substr (1). Match (reg)

If (r! = null) return unescape (r [2]); return null

}

}) (jQuery)

Once the method is defined, we can get the parameter values in URL in the following ways.

Get the id value in URL: id=$.getUrlParam ("id")

Thank you for reading this article carefully. I hope the article "how to obtain url and url parameters for Jquery" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you 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