如何运行我用JavaScript编写的代码? [英] How do I run code I have written in JavaScript?
问题描述
我是初学者,我所做的就是练习在Codecademy中编写代码。在谷歌广泛搜索如何运行.js文件之后,我什么都没看到。我假设我问的是错误的问题,我确信它很简单,但我找不到任何东西。
I am a beginner, all I have done is practiced writing code in Codecademy. After extensive searches of google for how to run a .js file, I turned up nothing. I assume I am asking the wrong question, and I am sure it is simple, but I couldn't find anything.
推荐答案
- 打开一个编辑器。最简单的一个是记事本
-
在下面写下基本HTML
- open an editor. Simplest one is notepad
Write basic HTML there like below
<html>
<head>
</head>
<body>
Hello World!
</body>
</html>
添加一个脚本标签并在其中写下你的js,如下所示
Add a script tag and write your js inside it like below
<html>
<head>
<script>
alert("hello");
</script>
</head>
<body>
Hello World!
</body>
</html>
或者您可以将js代码写入文件并另存为.js文件和链接在上面的代码中
or you can write your js code in a file and save as .js file and link that in the above code
<html>
<head>
<script src="myScript.js"></script>
</head>
<body>
Hello World!
</body>
</html>
将此保存为yourfile.HTML并在任何浏览器中打开
Save this as yourfile.HTML and open in any browser
这是一个了解更多信息的链接: http://www.w3schools.com/js/js_whereto.asp 。
Here's a link to learn more: http://www.w3schools.com/js/js_whereto.asp.
这篇关于如何运行我用JavaScript编写的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!