html代码
<script type="text/javascript" src="t.js?test=1&test2=3&test3=tangyang&test4=xxxxxxxxxxxxx"></script>
js代码
urlParameters = (function(script){
var l = script.length;
for(var i = 0; i < l; i++){
me = !!document.querySelector ? script[i].src : script[i].getAttribute('src',4);
if( me.substr(me.lastIndexOf('/')).indexOf('menu_hover') !== -1 ){
break;
}
}
return me.split('?')[1];
})(document.getElementsByTagName('script'))
/*!
* 获取url参数值函数
*/
GetParameters = function ( name ){
if( urlParameters && urlParameters.indexOf('&') > 0 ){
var parame = urlParameters.split('&'), i = 0, l = parame.length, arr;
for(var i=0 ; i < l; i++ ){
arr = parame[i].split('=');
if( name === arr[0] ){
return arr[1];
}
}
}
return null;
}
alert(GetParameters('test4'));