gpt4 book ai didi

javascript - 在tinymce编辑器中加载html文件作为初始内容

转载 作者:行者123 更新时间:2023-11-28 06:50:17 30 4
gpt4 key购买 nike

我已经在我的asp.net mvc项目中设置了tinymce。我想将 html 文件加载到位于另一个目的地的 TinyMCE 编辑器内容中。

我关注了tiny Documentation但给出我的 html 文件的路径有点令人困惑。

tinyMCE.activeEditor.setContent('<span>some</span> html');

这是我的 cshtml 文件

@{ }
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>TinyMCE Example</title>
<!-- TinyMCE Script Reference -->
<script src="~/scripts/tinymce/tinymce.min.js"></script>
<!-- Script to wire up your TinyMCE editor -->
<script type="text/javascript" src="~/Scripts/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({

selector: "textarea",
theme: "modern",
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern imagetools"
],
toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
toolbar2: "print preview media | forecolor backcolor emoticons",
image_advtab: true,
templates: [
{title: 'Test template 1', content: 'Test 1'},
{title: 'Test template 2', content: 'Test 2'}
],

});
tinyMCE.activeEditor.setContent(Html);
</script>
</head>
<body>
<!-- This will automatically post to your Index method (that is decorated with a HttpPost attribute) -->
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div>
<!-- This will contain your HtmlContent and use the TinyMCE editor-->
@Html.TextAreaFor(model => model.HtmlContent)

<input type="submit" value="Create" />
</div>
}
</body>
</html>

This question也与我的问题有关,但它不包括如何为 html 文件提供路径的描述

更新1:

我尝试使用 jquery 将 html 加载到 TinyMCE 文本区域中,其描述见 this question

    @section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")


<script type="text/javascript">

$.get("myhtml.html", function (content) {

tinyMCE.activeEditor.setContent(content);
});

</script>
}

但似乎它也不起作用

最佳答案

您不能直接给出 setContent 函数的路径。您需要做的就是获取后端的 html 文件内容并将其发送到您的页面,然后使用 setContent 方法将其插入到编辑器中。

关于javascript - 在tinymce编辑器中加载html文件作为初始内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33014947/

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