[英]JavaScript newbie and trying to open a text file as HTML in Google Chrome. HOW?
Currently reading Beginning JavaScript and it's asking me to open up a text file with HTML code that I've saved to my HD in my browser.目前正在阅读Beginning JavaScript ,它要求我打开一个文本文件,其中包含我在浏览器中保存到 HD 的 HTML 代码。 This might be easier in other browsers, but I'm using Google Chrome.这在其他浏览器中可能更容易,但我使用的是谷歌浏览器。
I've searched all over Google and the only answers i can find are how to make code appear as text, but I'm trying to the opposite.我在谷歌上搜索过,我能找到的唯一答案是如何使代码显示为文本,但我正试图相反。 Make text appear as what the code is commanding.使文本显示为代码命令的内容。
EDIT: 5/12/16 1:53AM Eastern time编辑:5/12/16 1:53AM 美国东部时间
All of your comments were very helpful!您的所有评论都非常有帮助! Thanks for the swift responses.感谢您的迅速回复。 they solved my issue.他们解决了我的问题。 I literally just wanted to view the code text as HTML in my browser and yes I am also typing into Notepad for now.我真的只是想在我的浏览器中以 HTML 格式查看代码文本,是的,我现在也在记事本中输入。 I'll work on my terminology.我将研究我的术语。
Thanks again for the help.再次感谢您的帮助。
You should convert the file to a HTML file.您应该将文件转换为 HTML 文件。
If you have a text editor like Sublime Text, Notepad++ or (my favorite) Programmers Notepad, open your file in the text editor and save it as a .html file.如果您有文本编辑器,如 Sublime Text、Notepad++ 或(我最喜欢的)程序员记事本,请在文本编辑器中打开您的文件并将其另存为 .html 文件。 All you need to do is change the file extension (the bit at the end) from .txt to .html您需要做的就是将文件扩展名(末尾的位)从 .txt 更改为 .html
If you don't have a text editor, notepad will work (in Windows, not sure about mac or linux).如果您没有文本编辑器,记事本也可以使用(在 Windows 中,不确定 mac 或 linux)。
Then just double click the file and it should open in Chrome.然后只需双击该文件,它就会在 Chrome 中打开。
If I got you right, you are studying some javascript code and you want to test the .txt snippets and run it in html or you want to just use the pre-made .txt file as html code.如果我猜对了,您正在学习一些 javascript 代码并且想要测试 .txt 片段并在 html 中运行它,或者您只想使用预制的 .txt 文件作为 html 代码。
If its case one如果它的情况一
Create a new HTML file using notepad or equivalent software, create a "<script>" element and embed your snippet there使用记事本或等效软件创建一个新的 HTML 文件,创建一个“<script>”元素并将您的代码片段嵌入其中
<script> Your code here (if its only javascript code)</script>
and save it, now drag and drop the file in browser.并保存它,现在将文件拖放到浏览器中。
If its case 2如果它的情况 2
Open the .txt file in notepad or equivalent go to save as, save it with .html extension or you can even just right click on it and change .txt to .html -> now drag and drop the file in chrome.在记事本或等效文件中打开 .txt 文件,然后将其另存为,使用 .html 扩展名保存,或者您甚至可以右键单击它并将 .txt 更改为 .html -> 现在将文件拖放到 chrome 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.