0

我有一个 tinymce 的视频上传,它将一些代码插入到编辑器中,如下所示:

var content2 = "<div class='playvideo' id='<?php echo $randomnumber;?>'>
<img class='posterimage' src='<?php echo $new_image_path; ?>'>
<a id='<?php echo $new_file; ?>' class='videoplaceholder'></a>
</div></div>";


parent.tinyMCE.execCommand('mceInsertContent', false,content2);

这工作正常,并输出:

<p><div id="581827" class="playvideo">
<img class="posterimage" src="/uploads/videos/images/1097VID.jpg" alt="" />
<a class="videoplaceholder" id="1097VID.mp4"></a>
</div></p>

但是插入这个内容后,我当然想继续写文字。但是当我这样做时,文本会放在 img 标签之后的我插入的内容中。像这样:

<p><div id="581827" class="playvideo">
<img class="posterimage" src="/uploads/videos/images/1097VID.jpg" alt="" />text i try to write goes here for some reason
<a class="videoplaceholder" id="1097VID.mp4"></a>
</div></p>

小提琴示例

当为新行单击 enter 时,它会创建第二个 div,其类与我插入的类相同。这是一种奇怪的行为。我读到 div 在段落中是非法的,但它也不适用于 span。

有没有人有任何指示?任何帮助是极大的赞赏。

4

1 回答 1

2

The problem of the text getting inserted after the img can be fixed by putting an &nbsp; as the link text i.e. instead of <a id='<?php echo $new_file; ?>' class='videoplaceholder'></a> you can use <a id='<?php echo $new_file; ?>' class='videoplaceholder'>&nbsp;</a>. I am not sure about the class though, may be there is a way to prevent TinyMCE from adding the class by default.

于 2012-07-24T09:16:44.717 回答