js location.search 用法详解

js location.search 用法详解JS中location.search什么意思?下面17javascript跟大家详细介绍一下:设置或获取网页地址跟在问号后面的部分当以get方式在url中传递了请求参数时,可以利用location的search属性提取参数的值,下面的代码把参数的名称和对应的值存储在2个数组中。functiontest(){varurl=window.location.se

JS中location.search什么意思?下面17javascript跟大家详细介绍一下:

设置或获取 网页地址跟在问号后面的部分

当以get方式在url中传递了请求参数时,可以利用location的search属性提取参数的值,下面的代码把参数的名称和对应的值存储在2个数组中。

<script>
function test()
{

var url=window.location.search;
if(url.indexOf(“?”)!=-1)
{
   var str = url.substr(1)
    strs = str.split(“&”);
    var key=new Array(strs.length);
    var value=new Array(strs.length);
    for(i=0;i<strs.length;i++)
    {
     key[i]=strs[i].split(“=”)[0]
     value[i]=unescape(strs[i].split(“=”)[1]);
    alert(key[i]+”=”+value[i]);
   }
}
}
< /script>

————————————————————–

< html>
< head><title>none</title>
< script>
function getParam(name){

var params=location.search.substring(1).toLowerCase();alert(‘params=’+params);
var paramList=[];
var param=null;
var parami;
if(params.length>0) {

if(params.indexOf(“&”) >=0) {

   paramList=params.split( “&” );
}else {

   paramList[0] = params;
}
for(var i=0,listLength = paramList.length;i<listLength;i++) {

   parami = paramList[i].indexOf(name+”=” );
   if(parami>=0) {

    param =paramList[i].substr(parami+(name+”=”).length);
   }
}
}
return param;
}
function check(){

id=document.getElementById(‘test’).value;alert(‘one’+id);
var userid=getParam(id);alert(‘two’+userid);

var flag=false;
var str=’2010001,2010002,2010003,2010004,2010005,2010006,2010007,2010008,2010009,2010010,2010011,2010012,2010013,2010014,2010015,2010016,2010017,2010018,2010019,2010020,2010021,2010022,2010023,2010024,2010025,2010026,2010027,2010028,2010029,2010030,2010031,2010032,2010033,2010034,2010035,2010036,2010037,2010038,2010039,2010040,2010041,2010042,2010043,2010044,2010045,2010046,2010047,2010048,2010049,2010050,2010051,2010052,2010053,2010054,2010055,2010056,2010057,2010058,2010059,2010060,2010061,2010062,2010063,2010064,2010065,2010066,2010067,2010068,2010069,2010070,2010071,2010072,2010073,2010074,2010075,2010076,2010077,2010078,2010079,2010080,2010081,2010082,2010083,2010084,2010085,2010086,2010087,2010088,2010089,2010090,2010091,2010092,2010093,2010094,2010095,2010096,2010097,2010098,2010099′;
var arr=str.split(‘,’);
for(var i=0,l=arr.length;i<l;i++){

if(userid == arr[i])
{

   flag=true;
   break;
}
}
if(!flag){

alert(‘demine!’);
return false;
}else{

alert(‘right’);
}
}
< /script>
< /head>
< body>
< table >
< form>
请输入<input type=”text” name=”test” id=”test”/>
< input type=”button” value=”确认”/>
< /form>
< /table>
< /body>
< /html>

来源:js location.search 用法详解



版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/37000.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注