问题描述
我们都知道在 PHP 中,通过使用 PHP 的 file_put_contents(file, data, mode, context)
函数,我们可以改变另一个文件的内容.
We all know that in PHP by using PHP's file_put_contents(file, data, mode, context)
function we can change the contents of another file.
JavaScript 有类似的功能吗?我的意思是我可以使用 JavaScript 更改文件的内容吗?
Does JavaScript have similar function? I mean can I change contents of a file by using JavaScript?
我有
<?php
$temp= file_get_contents('./inc/announcement.html');
require_once(FACULTY180_CLASS_ROOT.'TinyMCEMaker.php');
$richtext = new TinyMCEMaker('basic');
$richtext->editor('Description', $temp);
?>
<script>
function get_editor_content() {
//method1 getting the content of the active editor
var a = tinyMCE.activeEditor.getContent();
}
</script>
<button onclick="get_editor_content()">Save</button>
所以当点击保存"按钮时,我必须更新announcement.html"文件的内容?变量a"包含必须写入 html 文件的新数据.
So when Save button is clicked I have to update contents of the "announcement.html" file? varible "a" contains the new data that has to be wriitten to the html file.
我找到了答案并且有效:
I found the answer and it works:
<form action="Home.php" method="post" id="announcement">
<?php
$temp= file_get_contents('./path to html file');
require_once(the_class_name.'TinyMCEMaker.php');
$richtext = new TinyMCEMaker('basic');
$richtext->editor('Description', $temp);
?>
<input type="submit" name="formSubmit" value="Submit">
</form>
推荐答案
否
Javascript 是一个客户端脚本,您将无法使用 javascript 更改托管在服务器中的文件的内容
Javascript is a client side script, you will not be able to change the contents of a file hosted in server using javascript
这篇关于使用 JavaScript 更改 HTML 文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!