<script type="text/javascript" src="tongji.js?id=loginbox"></script>
就是如何获取id是多少了?
第一获取src
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
function getJsPath(jsname) { var js = document.scripts; var jsPath = ""; for (var i = js.length; i > 0; i--) { if (js[i - 1].src.indexOf(jsname) > -1) { return js[i - 1].src; }else{ return; } } return jsPath; }
|
第二从src中获取参数的值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
function getParam(jspath, parm){ if (typeof jspath=='undefined') {return "";} if (jspath.indexOf('?')>0) { var urlparse = jspath.split("\?"); }else{ return ""; } var parms = urlparse[1].split("&"); var values = {}; for(var i = 0; i < parms.length; i++) { var pr = parms[i].split("="); if (pr[0] == parm) return pr[1]; } return ""; }
|