调用的函数连接外部JavaScript文件 [英] Calling a function of en external javascript file
问题描述
在一般... ...我怎样才能让一个外部Java脚本文件的函数调用?
In general... How can I make a call on a function of an external java script file?
更具体的...
- 在头标记,我有
<脚本类型=文/ JavaScript的SRC =JScript中/ FontSize.js>< / SCRIPT>
-
外部JavaScript文件,(我想打电话给)
FontSize.js
包含以下功能。
function checkCookie()
function setCookie(c_name, value, expiredays)
function getCookie(c_name)
function increaseFontSize()
function decreaseFontSize()`
该FontSize.js位于〜/ Jscript脚本/
目录
我想上载的主体应该包含类似
I guess the body on load should contain something like
<身体的onload =/ JScript中/ Fontsize.js / checkCookie()>
当然没有什么作品,因为它应该,因为我不知道如何调用一个函数的外部JS文件
Of course nothing works as it should because, i do not know how to make the call to a function to an external js file
推荐答案
您只需要调用它,就好像它是本地:)
You just call it as if it were local :)
<body onload="checkCookie()">
或者,做脚本:
window.onload = checkCookie;
当你声明一个函数,它不是在另一个对象/命名空间,它只是全球可用,并且可以调用它,好像它马上preceded当前的code。默认情况下,这些功能将与窗口
对象,你可以在这里看到一个简短的演示对一>
When you declare a function and it's not in another object/namespace, it's just globally available, and you can call it as if it immediately preceded your current code. By default these functions will be on the window
object, you can see a short demo here.
例如(无关紧要的其中的这个函数的定义,外部与否):
For example (doesn't matter where this function's defined, external or not):
function myFunc() { alert('hi'); }
myFunc();
window.myFunc(); //same call, unless there's *another* myFunc in a local-er scope
这篇关于调用的函数连接外部JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!