html内引用js脚本可以传递参数?

来源:百度知道 编辑:UC知道 时间:2024/05/09 15:44:05
在html引用:
<script type="text/javascript" src="js/footer.js?type=2"> </script>

请问?type=2是什么意思?

footer.js内是怎么接受type=2呢? 谢谢!

var js = document.getElementsByTagName("script");
for(var i=0;i<js.length;i++){
if(js[i].src.indexOf("footer.js")>=0){
var arraytemp = new Array();
arraytemp = js[i].src.split('?');
arraytemp = arraytemp[1].split('=');
alert(arraytemp[0]+"="+arraytemp[1]);
}
}
你把这个写在footer.js的脚本内 就能读出来type=2

footer.js 中可以这么样接收 参数 type

// ==============================

var type = null;
(function() {
var scripts = document.scripts || document.getElementsByTagName("script");
var thisScript = scripts[scripts.length-1];
type = decodeURIComponent((thisScript.src.match(/[?&]type\=([^&#]+)/i)||["",""])[1]);
})();

// alert(type);