简体   繁体   English

如何连接 JavaScript 和 Html

[英]How to connect JavaScript and Html

So i want to connect my array from javaScript to my html, some one can explain how can i do that?所以我想将我的数组从 javaScript 连接到我的 html,有人可以解释我该怎么做? i am only able to find when the javascript is in the same html.我只能找到 javascript 何时在同一个 html 中。

html file: rest of the code in html ... html 文件:html 中的其余代码...

    <label for="eye">Which eye color does the character have?</label>
    <select name="eye" id="eye">
  <option value="blue">Blue</option>
  <option value="brown">Brown</option>
  <option value="green">Green</option>
</select>

<script>
    src = "js/eindopdracht.js"
</script>

js file: js文件:

var eyeColors = ["blue", "brown","green"];

the correct tag for you to use is is:您使用的正确标签是:

<script src="js/eindopdracht.js"></script>

this is how to include an external javascript file.这是如何包含外部 javascript 文件。

If you want to add javascript code inline then you would do:如果要内联添加 javascript 代码,则可以执行以下操作:

<script>
  console.log("this is inline javascript");
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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