gpt4 book ai didi

javascript - Tinymce 不保存或提交我的内容

转载 作者:搜寻专家 更新时间:2023-10-31 21:55:47 24 4
gpt4 key购买 nike

我不是专业程序员,我没有使用 Javascript 的经验,所以这个 Tinymce 让我感到困惑。基本上我的客户想在不接触代码的情况下自己更新内容,所以我必须设置这个 Tinymce,这样他就可以直接在浏览器上编辑内容。我已按照说明安装 Tinymce,但是当我单击提交时,没有任何反应。当我点击保存时,它会将我链接到 PHP 页面及其代码。以下是我的所有代码。请告诉我我需要做什么。

在 HTML 页面中:

<script type="text/javascript" src="tinymce/js/tinymce/tinymce.min.js"></script>

<script>
tinymce.init({
selector: "textarea#elm1",
theme: "modern",
width: 800,
height: 600,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor"
],
content_css: "css/content.css",
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons",
style_formats: [
{title: 'Bold text', inline: 'b'},
{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
{title: 'Example 1', inline: 'span', classes: 'example1'},
{title: 'Example 2', inline: 'span', classes: 'example2'},
{title: 'Table styles'},
{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
],

setup: function (editor) {
editor.on('change', function () {
tinymce.triggerSave();
});
}
});

</script>

<script type="text/javascript">
$(function(){

var url = "news.php";

$("#SubmitBtn").click(function(){
//"content" will PHP variable
$.post(url, { "page_content" : tinyMCE.activeEditor.getContent() }, function(respond){

if ( respond == ){
alert('Content saved to file');
return;
} else {
//Error message assumed
alert(respond);
}
});
});

});

</script>

形式:

<form method="post" action="news.php">
<textarea id="elm1" name="page_content">The content I wanna edit</textarea>
<input type="button" id="SubmitBtn" value="Submit"/>
</form>

在 PHP 页面中:

<?php

if ( isset($_POST['page_content']) ){

//This is what you want - HTML content from tinyMCE
//just treat this a string

if ( save_html_to_file($_POST['page_content'], 'news.html') ){
//Print 1 and exit script
die(1);
} else {
die('Couldnt write to stream');
}
}

/**
*
* @param string $content HTML content from TinyMCE editor
* @param string $path File you want to write into
* @return boolean TRUE on success
*/
function save_html_to_file($content, $path){
return (bool) file_put_contents($path, $content);
}

最佳答案

尝试将此代码添加到提交按钮

onclick="tinyMCE.triggerSave(true,true);"

关于javascript - Tinymce 不保存或提交我的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33931555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com