如何在浏览器中本地执行.js文件? [英] How do I execute .js files locally in my browser?

查看:1518
本文介绍了如何在浏览器中本地执行.js文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想知道如何在Mac上的textmate上键入一个javascript游戏,并且只有一个常规的.js文件,但是没有将.js文件打开并使其在chrome中运行,就像我说的那样:你好,世界!"比世界你好!会显示在chrome中.

Hello i was wondering how i can type a javascript game on textmate with my mac and have just a regular .js file but than take the .js file and open it and have it run in chrome like if i have it say "Hello World!" than Hello World! would show up in chrome.

此视频中的一个我所追求的例子: http://vimeo.com/105955605

An example of what I'm after is in this video: http://vimeo.com/105955605

推荐答案

视频中大约1:51,请注意她是如何在其中放置<script>标签的?它的工作方式是这样的:

Around 1:51 in the video, notice how she puts a <script> tag in there? The way it works is like this:

在计算机上的某个地方创建一个html文件(这是一个以.html结尾的文本文件).在您放置index.html的同一文件夹中,放置一个javascript文件(这只是一个以.js结尾的文本文件-我们将其称为game.js).然后,在您的index.html文件中,放入一些包含game.js脚本标记的html,就像玛丽在视频中所做的那样. index.html应该看起来像这样:

Create an html file (that's just a text file with a .html ending) somewhere on your computer. In the same folder that you put index.html, put a javascript file (that's just a textfile with a .js ending - let's call it game.js). Then, in your index.html file, put some html that includes the script tag with game.js, like Mary did in the video. index.html should look something like this:

<html>
    <head>
        <script src="game.js"></script>
    </head>
</html>

现在,在finder中双击该文件,它应该会在浏览器中打开.要打开控制台以查看JavaScript代码的输出,请点击Command-alt-j(同时按下三个按钮).

Now, double click on that file in finder, and it should open it up in your browser. To open up the console to see the output of your javascript code, hit Command-alt-j (those three buttons at the same time).

祝您旅途愉快,希望它对您而言和我迄今为止一样有趣:)

Good luck on your journey, hope it's as fun for you as it has been for me so far :)

这篇关于如何在浏览器中本地执行.js文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆