[英]calling one js function from other js file?
I have two .js files(A,B). 我有两个.js文件(A,B)。 i want to call functions of B.js into A.js file. 我想将B.js的函数调用到A.js文件中。 How can i'll be done. 我怎么能完成。
A.js: A.js:
function validation(){
alert("validating...");
}
B.js: B.js:
function login(){
// i want to call validation() of file A.js here. How can it possible
validation();
}
include the a.js file to b.js 将a.js文件包含在b.js中
function includeJs(ajsfilepath) {
var js = document.createElement("script");
js.type = "text/javascript";
js.src = jsFilePath;
document.body.appendChild(js);
}
includeJs("/path/a.js");
If you don't want to use scripting to dynamically include the javascript files, you can add the following lines in your html file: 如果您不想使用脚本动态包含javascript文件,可以在html文件中添加以下行:
<script src="A.js" type="text/javascript"></script>
<script src="B.js" type="text/javascript"></script>
Then, it should work. 然后,它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.