简体   繁体   中英

Can't embed text from js file in html file

I have a js file. In this file there is defiend some texts. It will be include with that tag

<script src="javascripts/resources.default.js" type="text/javascript"></script>

Here is the defined text.

menu_lacalize = {
    programm: "Programm",
    work: "Arbeit",
    nextPoint: "Naechster Punkt"
};

Ans the html file in which i am including this defined text :

<script type="text/javascript">menu_lacalize.programm;</script>

but it shows me nothing. In the console is no error and when i am alerting this it does not shows me the defined text.

Thanks in advance

Have you tried something like this:

<script src="javascripts/resources.default.js" type="text/javascript"></script>

<script type="text/javascript">
   document.getElementById('program').innerHTML = menu_lacalize.program;
</script>

Html markup

<ul>
  <li id="program"></li>
</ul>

Should result in

<ul>
  <li id="program">Programm</li>
</ul>

Try this:

<li>
    <script type="text/javascript">
        document.write(menu_lacalize.programm);
    </script>
</li>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM