Tinymce textarea无法正确显示

时间:2019-06-06 01:30:25

标签: html css tinymce

textarea正在显示html标签和WYSIWIG编辑器。如何不显示带有html标签和编辑器的文本区域。

我加载了以下js和CSS链接。

Scripts loaded

<h1>Incident Notes</h1>
<p></p>
<div class="form-group">
    <input hidden="hidden" name="id" th:value="${incident.id}" /> <label
        for="location">Incident Reference No: </label> <span
        th:text="${incidentRefNo}" />
</div>
<form action="@{/incidentNotes/update}" method="post">
    <input class="form-control" type="text" name="tempNotes"
        id="tempNotes" th:value="${tempNotes}" readonly="readonly"
        hidden="hidden" />
    <textarea id="myTextarea">

  </textarea>


    <hr />

    <div class="form-group ">
        <a class="btn btn-info btn-lg btn-block login-button"
            th:href="@{/incidentDetail?id=}+${incident.id}">Back</a>
    </div>
</form>

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

                        tinymce
                                .init({
                                    selector : '#myTextarea',
                                    skin : "oxide-dark",
                                    height : 800,
                                    plugins : [
                                            "advlist autolink lists link charmap print preview anchor",
                                            "searchreplace visualblocks",
                                            "insertdatetime table contextmenu paste save" ],
                                    toolbar : " save | print | insertfile undo redo |styleselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent",
                                    init_instance_callback : function(
                                            editor) {
                                        var tempNotes = $('#tempNotes')
                                                .val();
                                        console.log(tempNotes);
                                        tinymce.get('myTextarea')
                                                .setContent(tempNotes);
                                    },
                                    save_onsavecallback : function() {
                                        var content = tinymce.activeEditor
                                                .getContent();
                                        console.log(content);

                                        var url_string = window.location.href;
                                        var url = new URL(url_string);
                                        var incidentId = url.searchParams
                                                .get("id");
                                        console.log("Incident ID: "
                                                + incidentId);

                                        var oldURL = window.location.href
                                        var index = 0;
                                        var newURL = oldURL;
                                        index = oldURL.indexOf('?');
                                        if (index == -1) {
                                            index = oldURL.indexOf('#');
                                        }
                                        if (index != -1) {
                                            newURL = oldURL.substring(0,
                                                    index);
                                        }

                                        var path = newURL + '/update';

                                        $
                                                .ajax({
                                                    type : 'post',
                                                    cache : false,
                                                    url : path,
                                                    data : {
                                                        content : content,
                                                        incidentId : incidentId
                                                    },
                                                    success : function() {
                                                        tinymce.activeEditor.windowManager
                                                                .alert("This page has been successfully saved");
                                                    }
                                                });
                                    }
                                });
                    });
</script>

显示以下内容。 textarea正在显示已加载的html。我如何加载编辑器?

Result

请帮助

1 个答案:

答案 0 :(得分:0)

您似乎正在设置TinyMCE编辑器的值,并且紧接其前的<input />设置为tempNotes的值。您确定此输入字段已正确隐藏吗?

   <input class="form-control" type="text" name="tempNotes"
        id="tempNotes" th:value="${tempNotes}" readonly="readonly"
        hidden="hidden" />

根据MDN,隐藏输入的语法为:

<input id="prodId" name="prodId" type="hidden" value="xm234jq">

如果您出于测试目的删除了该输入,您仍然看到HTML字符串吗?