Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
How to combine javascript modules with javascript code in html

In my application I have my javascript in files. I am trying to convert those files to javascript modules.

I need to have some code in my html (in order to generate Django urls - (see this question How to configure a django url correctly in 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

setText('module')

This does not seem to work with modules

If I convert the html as follows

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

I get the error

module.js:1 Uncaught ReferenceError: setText is not defined

If I need to import the setText function into module.js, how do I do it?

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda