本文介绍了JavaScript 获取 url 段和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经阅读了一些问题,但我仍然不知道如何去做
我有一个网址 example.com/event/14aD9Uxp?p=10
I've read some question but I still can't figure out how to do it
I have a url example.com/event/14aD9Uxp?p=10
这里我想得到 14aD9Uxp
和 p
的值我试过使用 split('/'+'?p=')
但它不起作用
我想使用正则表达式,但我真的不明白如何使用它
Here I want to get the 14aD9Uxp
and the value of p
I've tried using split('/'+'?p=')
but it doesn't work
I want to use regex but I dont really understand how to use it
推荐答案
var URL='example.com/event/14aD9Uxp?p=10';
var arr=URL.split('/');//arr[0]='example.com'
//arr[1]='event'
//arr[2]='14aD9Uxp?p=10'
var parameter=arr[arr.length-1].split('?');//parameter[0]='14aD9Uxp'
//parameter[1]='p=10'
var p_value=parameter[1].split('=')[1];//p_value='10';
这篇关于JavaScript 获取 url 段和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!