从另一个文件访问函数

时间:2022-06-30 02:48:43

I have two file:

我有两个文件:

html2canvas.js

function html2canvas(){

}

myid_print.js

(function ($) {  
    $(document).ready(function() {        
        //I want to call html2canvas function here
        html2canvas();
    });
})(jQuery);

I already included both files in my html but after running the code above, the console shows an error saying:

我已经在我的html中包含了这两个文件但是在运行上面的代码后,控制台显示错误说:

Uncaught ReferenceError: html2canvas is not defined

How will I call the function from inside my second file?

如何从第二个文件中调用该函数?

2 个解决方案

#1


Try implementing your Client side code as :

尝试将您的客户端代码实现为:

<head>
....
    <script src="html2canvas.js" type="text/javascript"></script> 
    <script src="myid_print.js" type="text/javascript"></script> 
....
<head>
<body>
...
    <script type="text/javascript">
       function_from_myid_print();
    </script>
...
</body>

Inside which you can call html2canvas();

在其中你可以调用html2canvas();

This will surely help you.

这肯定会对你有所帮助。

For more details refer links:

有关详细信息,请参阅链接

https://*.com/a/3809896/4763053 and https://*.com/a/25963012/4763053

https://*.com/a/3809896/4763053和https://*.com/a/25963012/4763053

#2


Try put your JS script at the bottom of your HTML page.

尝试将您的JS脚本放在HTML页面的底部。

#1


Try implementing your Client side code as :

尝试将您的客户端代码实现为:

<head>
....
    <script src="html2canvas.js" type="text/javascript"></script> 
    <script src="myid_print.js" type="text/javascript"></script> 
....
<head>
<body>
...
    <script type="text/javascript">
       function_from_myid_print();
    </script>
...
</body>

Inside which you can call html2canvas();

在其中你可以调用html2canvas();

This will surely help you.

这肯定会对你有所帮助。

For more details refer links:

有关详细信息,请参阅链接

https://*.com/a/3809896/4763053 and https://*.com/a/25963012/4763053

https://*.com/a/3809896/4763053和https://*.com/a/25963012/4763053

#2


Try put your JS script at the bottom of your HTML page.

尝试将您的JS脚本放在HTML页面的底部。