简体   繁体   English

您如何使用Javascript读取,写入和创建“ .txt”文件?

[英]How can you read, write, and create “.txt” files using Javascript?

I am writing a website and I have a very basic understanding of JavaScript (JS) but a good understanding of HTML and CSS . 我正在写一个网站,我对JavaScript(JS)有非常基本的了解,但对HTMLCSS有很好的了解。 I want to have an admin part of the website were you can edit the content of the site. 我想拥有网站的管理部分,以便您可以编辑网站的内容。 I also need help on how to display these text files onto the website using JS. 我还需要有关如何使用JS将这些文本文件显示到网站上的帮助。 Thank you for your help. 谢谢您的帮助。

No. You can't. 不,你不能。 For this you will need backend server software, like PHP. 为此,您将需要后端服务器软件,例如PHP。

You can do it with ActiveX objects - http://www.yaldex.com/wjscript/jsfilecreateTextFile.htm - but you're tying yourself to proprietary IE support. -您可以使用ActiveX对象做http://www.yaldex.com/wjscript/jsfilecreateTextFile.htm -但你绑自己专有的IE浏览器的支持。

Other than that, you'll need a server-side language such as PHP. 除此之外,您还需要服务器端语言,例如PHP。

In HTML5 you can operate on local files via the File API (have a look at http://www.html5rocks.com/en/tutorials/file/dndfiles/ for a quick tutorial) but manipulating files on the server using JavaScript on its own is impossible. 在HTML5中,您可以通过File API对本地文件进行操作(有关快速教程, 请参见http://www.html5rocks.com/zh-cn/tutorials/file/dndfiles/ ),但可以使用服务器上的JavaScript来处理服务器上的文件自己是不可能的。 You need to use AJAX to send a request to a PHP (or some other server-side language) script to do it for you. 您需要使用AJAX将请求发送到PHP(或其他服务器端语言)脚本才能为您完成请求。

不可能,只有服务器端语言

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

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