本文介绍了如何从Javascript中的URL中提取GET参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这个网址:
s = 'http://mydomain.com/?q=microsoft&p=next'
在这种情况下,如何从字符串中提取microsoft ?
我知道在python中,它会是:
In this case, how do I extract "microsoft" from the string?I know that in python, it would be:
new_s = s[s.find('?q=')+len('?q='):s.find('&',s.find('?q='))]
推荐答案
我使用这里提供的parseUri库:
I use the parseUri library available here:http://stevenlevithan.com/demo/parseuri/js/
它可以让您完全满足您的要求:
It allows you to do exactly what you are asking for:
var uri = 'http://mydomain.com/?q=microsoft&p=next';
var q = uri.queryKey['q'];
// q = 'microsoft'
这篇关于如何从Javascript中的URL中提取GET参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!