如何使模板内容在tinymce中不可编辑

时间:2022-09-12 08:52:14

I've crated html template file, I put some elements inside that template are non editable.

我已经创建了html模板文件,我在该模板中放置了一些元素是不可编辑的。

template.html contains

template.html包含

<body>
<div>This is a sample template </div>
<div contenteditable="false" style="color:red">Read Only Text</div>
</body>

on inserting this template file into the textarea the second div is editable, while inspecting over that div I've seen that the attribute contenteditable="false" is not there on insert, but its there on the preview before the insert of template.

在将此模板文件插入textarea时,第二个div是可编辑的,同时检查该div我已经看到属性contenteditable =“false”不在插入,但它在插入模板之前的预览中。

Any help gratefully received!

任何帮助感激不尽!

1 个解决方案

#1


2  

From this page: http://www.tinymce.com/tryit/noneditable_content.php

从此页面:http://www.tinymce.com/tryit/noneditable_content.php

Its using a textarea:

它使用textarea:

  <textarea name="content" style="width:100%">
    &lt;p&gt;Text with a &lt;span class="mceNonEditable"&gt;[non editable]&lt;/span&gt; inline element.&lt;/p&gt;
    &lt;p class="mceNonEditable"&gt;Noneditable text block with &lt;span class="mceEditable"&gt;[editable]&lt;/span&gt; items within.&lt;/p&gt;
    &lt;p&gt;Text with tokens that isn't [[editable]] since they match the noneditabe_regexp.&lt;/p&gt;
  </textarea>

The key here is putting a class of mceNonEditable in your element:

这里的关键是在你的元素中放入一类mceNonEditable:

span class="mceNonEditable"

Then whatever non-editable content you have, wrap it in greater than and less than:

然后,无论您拥有哪些不可编辑的内容,请将其包含在大于和小于:

&gt;You cannot edit me&lt;

Then finally close the element:

然后最后关闭元素:

/span

I think you can also change the mode (in the example they're using textareas, so I guess you can also use divs or spans) when initializing tinymce:

我认为你也可以在初始化tinymce时改变模式(在示例中他们使用textareas,所以我猜你也可以使用div或spans):

tinyMCE.init({
        mode : "textareas",
        noneditable_regexp: /\[\[[^\]]+\]\]/g
});

There's also noneditable_regexp which lets you specify a regular expression of non-editable contents. I think this is easier than using html entities.

还有noneditable_regexp,它允许您指定不可编辑内容的正则表达式。我认为这比使用html实体更容易。

I haven't actually tried it but that's the way I interpret the example in the page.

我还没有尝试过,但这就是我在页面中解释示例的方式。

#1


2  

From this page: http://www.tinymce.com/tryit/noneditable_content.php

从此页面:http://www.tinymce.com/tryit/noneditable_content.php

Its using a textarea:

它使用textarea:

  <textarea name="content" style="width:100%">
    &lt;p&gt;Text with a &lt;span class="mceNonEditable"&gt;[non editable]&lt;/span&gt; inline element.&lt;/p&gt;
    &lt;p class="mceNonEditable"&gt;Noneditable text block with &lt;span class="mceEditable"&gt;[editable]&lt;/span&gt; items within.&lt;/p&gt;
    &lt;p&gt;Text with tokens that isn't [[editable]] since they match the noneditabe_regexp.&lt;/p&gt;
  </textarea>

The key here is putting a class of mceNonEditable in your element:

这里的关键是在你的元素中放入一类mceNonEditable:

span class="mceNonEditable"

Then whatever non-editable content you have, wrap it in greater than and less than:

然后,无论您拥有哪些不可编辑的内容,请将其包含在大于和小于:

&gt;You cannot edit me&lt;

Then finally close the element:

然后最后关闭元素:

/span

I think you can also change the mode (in the example they're using textareas, so I guess you can also use divs or spans) when initializing tinymce:

我认为你也可以在初始化tinymce时改变模式(在示例中他们使用textareas,所以我猜你也可以使用div或spans):

tinyMCE.init({
        mode : "textareas",
        noneditable_regexp: /\[\[[^\]]+\]\]/g
});

There's also noneditable_regexp which lets you specify a regular expression of non-editable contents. I think this is easier than using html entities.

还有noneditable_regexp,它允许您指定不可编辑内容的正则表达式。我认为这比使用html实体更容易。

I haven't actually tried it but that's the way I interpret the example in the page.

我还没有尝试过,但这就是我在页面中解释示例的方式。