我正在动态设置HTML之后尝试设置tinyMCE文本区域的内容。
链接到CodePen示例:https://codepen.io/xanabobana/pen/oNxwgzX
重新创建步骤:
我尝试过动态地重新初始化和设置内容,但这没有用。这是我的代码:
var newsModalHTML = $("#newsModalDiv").html();
tinymce.init({
selector: "#mytextarea",
plugins: "image, link",
tinycomments_mode: "embedded"
});
//replace news modal with image modal when adding a new image
$("#newImageButton").click(function() {
newsModalHTML = $("#newsModalDiv").html();
$("#newsModal").modal('toggle');
$("#newFileModal").modal('toggle');
});
//show the news modal when the file modal is closed
$("#closeUploadFile").click(function() {
$("#newsModalDiv").html(newsModalHTML);
tinymce.EditorManager.editors = [];
tinymce.init({
selector: "#mytextarea",
plugins: "image, link", });
tinymce.get("mytextarea").setContent("hello world");
$("#newsModal").modal('toggle');
$('#fldNewTitle').focus();
});
<button type="button" data-toggle="modal" data-target="#newsModal">+Add News Article</button>
<!--hidden edit article div-->
<div id="newsModalDiv" style="max-height:90%; overflow:scroll;">
<div class="modal fade" id="newsModal" tabindex="-1" role="dialog" aria-labelledby="newFileModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content modalwidth">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="newFileModalLabel">Edit News Article</h4>
</div>
<div class="modal-body">
<form> <textarea id="mytextarea" name="mytextarea">test text</textarea></form>
<button type="button" id="newImageButton">Upload New Image</button>
</div>
<div class="modal-footer">
<span style="float:right"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="newArticleSubmit">Save</button></span></div>
</div>
</div>
</div>
</div>
</div>
<!--hidden upload image div-->
<div id="newFileModalDiv">
<div class="modal fade" id="newFileModal" role="dialog" aria-labelledby="newFileModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content modalwidth">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="newFileModalLabel">Upload a New Image</h4>
</div>
<div class="modal-body">
<section class="col-md-12">
<article>
<p>Use this form to upload an image to the database for the current project.</p><br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" id="closeUploadFile">Close</button>
<button type="button" class="btn btn-primary" id="submitNewFile">Upload Image</button>
</div>
</div>
</div>
</div>