18910140161

如何将javascript模块与HTML-Stack溢出中的javascript代码结合在一起

顺晟科技

2022-10-19 13:04:16

221

在我的应用程序中,我有我的javascript文件。我正在尝试将这些文件转换为javascript模块。

我需要在html中包含一些代码(为了生成Django URL-(请参见此问题How to configure a Django url,在JavaScript中正确配置)。

HTML

<html>
    <head>
    </head>
    <body>
        <p id="display_text">aaa</p>
    </body>

    <script type="">
        function setText(text) {
            var display_text = document.getElementById('display_text');
            display_text.innerText = text;
        }
    </script>
    <script type="" src="module.js"></script>
</html>

module.js

<html>
    <head>
    </head>
    <body>
        <p id="display_text">aaa</p>
    </body>

    <script type="">
        function setText(text) {
            var display_text = document.getElementById('display_text');
            display_text.innerText = text;
        }
    </script>
    <script type="" src="module.js"></script>
</html>

这似乎不适用于模块

如果按以下方式转换html

<html>
    <head>
    </head>
    <body>
        <p id="display_text">aaa</p>
    </body>

    <script type="">
        function setText(text) {
            var display_text = document.getElementById('display_text');
            display_text.innerText = text;
        }
    </script>
    <script type="" src="module.js"></script>
</html>

我得到错误

module.js:1未捕获的引用Error:未定义setText

如果需要将settext函数导入到module.js中,如何操作?

我做错了什么?


顺晟科技:

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航