87,904
社区成员
发帖
与我相关
我的任务
分享
<script language=javascript>
function getValue(key,str){
try{ return str.match(new RegExp(key+'=(\\w+)&?'))[1];}catch(e){alert('no value of '+key);return null}
}
function get(o){
alert(getValue(o.value,document.getElementById('content' ).value));
}
</script>
<input id='content' type="text" value="index2.php?option=content&task=showcategory&fun=show" />
<input type="button" value='option' onclick="get(this)"/>
<input type="button" value='task' onclick="get(this)"/>
<input type="button" value='fun' onclick="get(this)"/>
<input type="button" value='error' onclick="get(this)"/>
function getValue(key,str){
try{
return str.match(new RegExp(key+'=(\\w+)&?'))[1];
}catch(e){
alert('no value of '+key);
return null;
}
}
function getValue(key,str){
return str.match(new RegExp(key+'=(\\w+)&?'))[1];
}
function getValue(key,str){
var a = str.split(/\?|=|&/);
for(var i=0,len=a.length;i<len;i++)if(a[i]==key)return a[i+1];
return null;
}
<script language=javascript>
function getValue(key,str){
return str.match(new RegExp(key+'=(\\w+)&'))[1];
}
</script>
<input id='content' type="text" value="index2.php?option=content&task=showcategory&fun=show" />
<input type="button" value='点点看' onclick="alert(getValue('task',document.getElementById('content' ).value))"/>
var text = 'index2.php?option=content&task=showcategory&fun=show';
var reg = /& *task *=.*&/ig;
var result = text.match(reg)[0];
result = result.slice(result.indexOf('=') + 1, -1);//result即為樓主要的值了
var s = "index2.php?option=content&task=showcategory&fun=show";
function getValue(key){
return s.match(new RegExp(key+'=(\\w+)&'))[1];
}
alert(getValue('task'));
var s = "index2.php?option=content&task=showcategory&fun=show";
function getValue(key){
var a = s.split(/\?|=|&/);
for(var i=0,len=a.length;i<len;i++)if(a[i]==key)return a[i+1];
return null;
}
alert(getValue('task'));