简体   繁体   English

如何在=登录jQuery后获取url的值

[英]How to get the value of url after = sign in jQuery

I want to get the value in jquery after the equal sign but i am not been able to get the value this is my url 我想在等号后获取jquery中的值,但是我无法获取这是我的url的值

https://dev.example.com/front-end-pm/?fepaction=newmessage&=Shammy%20Kothari

this is how i am trying to get the value after the = sign 这就是我试图获取=符号后的值的方式

var url      =window.location.href; 
var queryString = url.split('&', 2)[1] || '';

I am getting like this 我越来越像这样

=Shammy%20Kothari 麂皮=%20Kothari

I just Need 我只需要

Shammy Kothari 沙米·科塔里(Shammy Kothari)

You need to decode the url using decodeURIComponent() 您需要使用decodeURIComponent()对URL进行解码

 //var url =window.location.href; var url ="https://dev.example.com/front-end-pm/?fepaction=newmessage&=Shammy%20Kothari"; var str = decodeURIComponent(url.split('=').pop()); console.log(str); 

First thing you probably want to change is that the value in your url is not assigned to a name. 您可能要更改的第一件事是url中的值未分配给名称。 This would look like this: https://dev.example.com/front-end-pm/?fepaction=newmessage&YOUR_PARAMETER_NAME=Shammy%20Kothari After that you could use URLSearchParams as proposed here . 看起来像这样: https://dev.example.com/front-end-pm/?fepaction=newmessage&YOUR_PARAMETER_NAME=Shammy%20Kothari ://dev.example.com/front-end-pm/?fepaction=newmessage&YOUR_PARAMETER_NAME=Shammy%20Kothari之后,您可以按照此处建议的那样使用URLSearchParams。 This could look like the following: 看起来可能如下所示:

const urlParams = new URLSearchParams(window.location.search);
//If you don't want to retrieve the url from the url bar just use: const urlParams = new URLSearchParams('https://dev.example.com/front-end-pm/?fepaction=newmessage&YOUR_PARAMETER_NAME=Shammy%20Kothari');
const myParam = urlParams.get('YOUR_PARAMETER_NAME'); //would be 'Shammy Kothari'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM