[英]Uncaught ReferenceError: script is not defined
In jQuery, how do I call a function in a script that I retrieve via code? 在jQuery中,如何在通过代码检索的脚本中调用函数?
I have a javascript file called testjavascript.js
我有一个名为
testjavascript.js
的javascript文件
Here is the code: 这是代码:
function testfunctionwithdata(testdata)
{
alert(testdata);
}
function testfunction()
{
alert("testfunction");
}
I also have a javascript called testcalljavascriptfunction.js
我也有一个名为
testcalljavascriptfunction.js
的javascriptjavascript.function
Here is the code: 这是代码:
var scripturl = "/objects/testjavascript.js";
$.getScript(scripturl, function() {
script.testfunction();
});
When I load the testcalljavascriptfunction.js
script from an index.html
page, I am getting the following error in the console: 当我从
index.html
页面加载testcalljavascriptfunction.js
脚本时,在控制台中出现以下错误:
Uncaught ReferenceError: script is not defined
未捕获的ReferenceError:脚本未定义
There is no object called script
in your context, when the script file is loaded it is parsed and executed. 在您的上下文中没有称为
script
对象,加载脚本文件时将对其进行解析和执行。 Since your method seems to be in global context you can call it by using testfunction()
由于您的方法似乎在全局上下文中,因此可以使用
testfunction()
调用
var scripturl = "/objects/testjavascript.js";
$.getScript(scripturl, function() {
testfunction();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.