从查询字符串获取变量 [英] getting variable from query string

查看:98
本文介绍了从查询字符串获取变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我已经花了我的时间搜索,所以我现在要问< G>


我需要查看网址,如果存在变量在查询字符串中。


所以,如果我的地址栏看起来像:
http://www.domain.com?THIS=yes&that=...otherthing=154


我需要它来查找这个
如果这个存在,那么这是=是

然后MyVar =我的字符串在这里 ;

如果这不是=是

那么MyVar =不是这里的字符串

如果这不存在

然后MyVar =" not yes string here"

-


感谢您的时间,

juglesh B> {}}

hello, I''ve put in my time searching, so I''ll ask now<G>

I need to look at the url, if a variable is present in the query string.

so, if my address bar looks like:
http://www.domain.com?THIS=yes&that=...otherthing=154

I need it to look for THIS
if THIS is present, and THIS= yes
then MyVar = "my string here"
if THIS does not = yes
then MyVar = "not yes string here"
if THIS is not present
then MyVar = "not yes string here"
--

thanks for your time,
juglesh B>{)}

推荐答案



juglesh写道:

juglesh wrote:
你好我已经花了很多时间搜索,所以我会的sk now< G>

如果查询
字符串中存在变量,我需要查看url。
所以,如果我的地址栏看起来像:
http:// www。 domain.com?THIS=yes&that=...otherthing=154

我需要它来寻找这个
如果它存在,那么这是=是
然后MyVar =我的字符串在这里
如果这不是=是
那么MyVar =不是这里的字符串
如果这不存在那么
那么MyVar =不是这里的字符串

-

感谢您的时间,
juglesh B> {}}
hello, I''ve put in my time searching, so I''ll ask now<G>

I need to look at the url, if a variable is present in the query string.
so, if my address bar looks like:
http://www.domain.com?THIS=yes&that=...otherthing=154

I need it to look for THIS
if THIS is present, and THIS= yes
then MyVar = "my string here"
if THIS does not = yes
then MyVar = "not yes string here"
if THIS is not present
then MyVar = "not yes string here"
--

thanks for your time,
juglesh B>{)}




函数getQval(名称)

{

var m,Q = window.location.search.substring(1);

if(''''!= Q)

{

var re = new RegExp(escape(name)+''=([^&



function getQval(name)
{
var m, Q = window.location.search.substring(1);
if ('''' != Q)
{
var re = new RegExp(escape(name) + ''=([^&


+)'');

i f(m = Q.match(re))

返回m [1];

否则返回'''';

}

返回'''';

}


var MyVar =(getQval(''THIS'')==''是'')?

''我的字符串''''''这里不是字符串'';

+)'');
if (m = Q.match(re))
return m[1];
else return '''';
}
return '''';
}

var MyVar = (getQval(''THIS'') == ''yes'') ?
''my string here'' : ''not yes string here'';


On星期二,2004年12月21日16:09:41 GMT,juglesh< ju ***** @nospamRadioKDUG.com>

写道:


[snip ]
On Tue, 21 Dec 2004 16:09:41 GMT, juglesh <ju*****@nospamRadioKDUG.com>
wrote:

[snip]
http://www.domain.com?THIS=yes&that=...otherthing=154

我需要它来寻找这个
如果这个存在,那么这是=是
然后MyVar =我的字符串在这里
如果这不是=是
那么MyVar =不是这里的字符串
如果这不存在
然后MyVar =不是这里的字符串
http://www.domain.com?THIS=yes&that=...otherthing=154

I need it to look for THIS
if THIS is present, and THIS= yes
then MyVar = "my string here"
if THIS does not = yes
then MyVar = "not yes string here"
if THIS is not present
then MyVar = "not yes string here"




var url = document.URL,

i = url.indexOf(''THIS =''),

j = url.indexOf(''&' ',i);

if(-1 == j){j = url.length;}

if(( - 1 == i)|| (''是''!= url.substring(i + 5,j))){

/ *'''这''不存在或不等于''是' '* /

}


或更通用的东西:


/ *返回与a相关的值密钥在查询字符串中。

*

*如果密钥不存在或没有值,则未定义

*返回。

* /

函数getQueryValue(名称){

var url = document.URL,

i = url.indexOf(name + =''=''),

j = url.indexOf(''&'',i);

if( - 1 == j){j = url.length;}

if(-1!= i){return url.substring(i + name.length,j);}

}


if(''yes''!= getQueryValue(''THIS'')){

/ *''这个''不存在或不等于''是''* /

}


迈克


-

Michael Winter

替换.invalid&q UOT;与.uk通过电子邮件回复。



var url = document.URL,
i = url.indexOf(''THIS=''),
j = url.indexOf(''&'', i);
if(-1 == j) {j = url.length;}
if((-1 == i) || (''yes'' != url.substring(i + 5, j))) {
/* ''THIS'' doesn''t exist or is not equal to ''yes'' */
}

or for something more generic:

/* Returns the value associated with a key in the query string.
*
* If the key doesn''t exist or doesn''t have a value, undefined
* is returned.
*/
function getQueryValue(name) {
var url = document.URL,
i = url.indexOf(name += ''=''),
j = url.indexOf(''&'', i);
if(-1 == j) {j = url.length;}
if(-1 != i) {return url.substring(i + name.length, j);}
}

if(''yes'' != getQueryValue(''THIS'')) {
/* ''THIS'' doesn''t exist or is not equal to ''yes'' */
}

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


这篇关于从查询字符串获取变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆