location.search详解
JS中location.search什么意思
设置或获取⽹页地址跟在问号后⾯的部分
当以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(){
ElementById('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,20100 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="确认" onclick="javascript:check();"/>
</form>
</table>
</body>
</html>
>421事件是什么意思