如何给JavaScript文件传递参数
<%--这是引用js文件,并设置属性值--%> <mce:script type ="text/javascript" src="test.js" mce_src="test.js"><!-- ClientIds.a = '<%=ResolveUrl("~/WebServices")%>'; ClientIds.b = "<%=List.ClientID %>"; ClientIds.c = "c"; // --></mce:script>
在test.js文件里:
var scripts = document.getElementsByTagName('script'); var currentScript = scripts[scripts.length - 1]; //指定初始值,如果调用端没有设置该值,则采用默认初始值 //var ClientIds = { }; var ClientIds = { a: '/WebServices', b: 'bbb', c: 'test'}; eval(currentScript.innerHTML);//关键 alert(ClientIds.a); alert(ClientIds.b); alert(ClientIds.c);