1、定义全局变量
<script language="javascript"> var g = "I‘m here"; </script> <script tpye="text/javascript" src="test.js"></script>
处理:
alert(g);
2、在src后面传参
<script tpye="text/javascript" src="test.js?a=1&b=2" id="testjs"></script>
处理:
var test = document.getElementById("testjs"); var src = test.getAttribute("src");var result;if(src){ new RegExp("(^|&)" + name + "=([^&]*)").exec(src); result = RegExp.$2}alert(result);
3、检索js文件(js文件要最后引入)
<script tpye="text/javascript" src="test.js"> var temp = "just test"; </script>
处理:
var script = document.getElementsByTagName("script"); eval(script[script.length-1].innerHTML); alert(temp);
4、设置其他属性
<script id="testScript" type="text/javascript" src="test.js" data="a=b&c=d"></script>
处理:
var scriptArgs = document.getElementById(‘testScript‘).getAttribute(‘data‘);
时间: 2024-10-06 16:14:37