Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript更改HTML文件的内容_Javascript_Html - Fatal编程技术网

使用JavaScript更改HTML文件的内容

使用JavaScript更改HTML文件的内容,javascript,html,Javascript,Html,我们都知道,在PHP中,通过使用PHP的file\u put\u contents(文件、数据、模式、上下文)函数,我们可以更改另一个文件的内容 JavaScript有类似的功能吗?我的意思是,我可以使用JavaScript更改文件的内容吗 我有 <?php $temp= file_get_contents('./inc/announcement.html'); require_once(FA

我们都知道,在PHP中,通过使用PHP的
file\u put\u contents(文件、数据、模式、上下文)
函数,我们可以更改另一个文件的内容

JavaScript有类似的功能吗?我的意思是,我可以使用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> 

函数get_editor_content(){
//方法1获取活动编辑器的内容
var a=tinyMCE.activeEditor.getContent();
}
拯救
所以当点击保存按钮时,我必须更新“announcement.html”文件的内容吗?变量“a”包含必须写入html文件的新数据

我找到了答案,它是有效的:

  <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的服务器上更改文件-您需要服务器端代码。在某些非常特定的条件下,您可以使用Javascript在客户端上更改文件,但您的问题太广泛,无法给出具体的答案。您无法使用客户端上的Javascript更新服务器上的文件。您可以通过AJAX调用将新文本发送到服务器,但仍需要一些服务器端代码来执行更新。您必须使用PHP或其他服务器端语言,并在表单提交后保存内容。您可以看看这一点。您的体系结构是什么?您在服务器端使用什么语言?