jQuery- How to get the GET variable from a URL

php die

In my js file, I am outputting hyperlinks based on some data pulled from an API:

output += '<a class="reg_link" href="'+regObj.href+'?reg='+value+'" title="'+regObj.title+'" target="_blank">';

This works fine. However, later I want to find out what the ?reg= value is.

$(".reg_link").each(function() {
  // How do I get the GET variable from the URL?
});

I'm trying to grab whatever the value of the GET variable is. How do I do that?

JasonS

From How can I get query string values in JavaScript?

You don't need jQuery for that purpose. You can use just some pure JavaScript:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

Usage:

var reg = getParameterByName('reg');

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

jQuery URL GET变量

来自分类Dev

How to get the selected date from jquery datepicker

来自分类Dev

How to get track ID from URL using the SoundCloud API

来自分类Dev

How to get the parameter from a relative URL string in C#?

来自分类Dev

jQuery-如何从URL获取GET变量

来自分类Dev

jQuery-如何从URL获取GET变量

来自分类Dev

jQuery $ .get在标签之后剪切URL

来自分类Dev

从Bluebird Promise对象访问jQuery $ .get URL

来自分类Dev

使用 jQuery 从 URL 中获取 $_GET[]

来自分类Dev

Get data frame from character variable

来自分类Dev

Get/Set Workflow Variable from uiTypeEditor

来自分类Dev

Excel: Get max value from variable range

来自分类Dev

How to get type from String?

来自分类Dev

How can I get my meteor app to connect to a database with MONGO_URL env variable in Meteor Up (mup)?

来自分类Dev

How to get width of an element from an ng-click without Jquery in AngularJS?

来自分类Dev

通过jquery从html表单中获取Http Get url

来自分类Dev

GET data: net::ERR_INVALID_URL for jQuery Dialog

来自分类Dev

如何使用jQuery更新URL中的get参数

来自分类Dev

为什么jQuery.get()更改我的URL?

来自分类Dev

How to get a value from keyvalue pair list?

来自分类Dev

How to get the country code from CultureInfo?

来自分类Dev

How to get extreme points from UIImage

来自分类Dev

How to get a filename from an ImageView (ANDROID)

来自分类Dev

How to get the value from ArrayList<Object> in android

来自分类Dev

How to get status code from NSURLSessionDataTask?

来自分类Dev

How to get Wikipedia page from Wikidata Id?

来自分类Dev

How to get a particular element from Queue?

来自分类Dev

How to get input text from soft keyboard

来自分类Dev

How to get the id of a chrome app from an extension

Related 相关文章

热门标签

归档