简体   繁体   English

从外部脚本调用 Js 脚本 function

[英]Calling Js script function from external Scripts

Am trying to call a JS script from a function library in another script.我试图在另一个脚本中从 function 库中调用 JS 脚本。

Eg.例如。 iceCreams.Js contains ---> iceCreams.Js 包含 --->

iceCream(iceCreams){
var profit = .54

var Total = iceCreams * profits

return Total;

}

register.js contains --> register.js 包含 -->

dailyTotals(wages, iceCreams){

var total = iceCream(iceCreams);

var profit = iceCreaps - wages

return wages;
}

Any help pointing me in the right direction?!任何帮助指出我正确的方向?!

Make sure your page loads the iceCream.Js before the register.js :确保您的页面在register.js之前加载iceCream.Js

<html>
...
<script type="text/javascript" src="iceCream.Js"></script>
<!-- now you can use functions in iceCream.Js in your register.js -->
<script type="text/javascript" src="register.js"></script>
....
</html>

Running the javascripts is done in client side and after rendering the full html.在客户端运行 javascripts 并在渲染完整的 html 之后完成。 So, you have to add script tag for the library javascripts before consuming ones.因此,您必须在使用库之前为库 javascripts 添加脚本标签。 Just add script tag for the library before the one for register:只需在注册之前添加库的脚本标签:

<script type="text/javascript" src="iceCreams.Js"></script>
<script type="text/javascript" src="register.js"></script>

Both script files must be referenced on the page they are used.这两个脚本文件都必须在它们使用的页面上被引用。

Additionally, to get IntelliSense in Visual Studio to work within the script, add the following line to the top of register.js:此外,为了让 Visual Studio 中的 IntelliSense 在脚本中工作,将以下行添加到 register.js 的顶部:

/// <reference path="iceCreams.js" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM