TinyMCE 删除具有特定类的 DIV
我想从 TinyMCE 编辑器内容中删除具有特定类的 div。
在理想的世界中,我希望能够通过 valid_elements 选项来做到这一点,但我不知道它是否可以实现。
以下是编辑器内容的示例:
<div class="content">
Some html content here
<div class="anotherclass"></div>
</div>
我希望将其
<div class="content">
删除,以便编辑器仅显示此内容:
Some html content here
<div class="anotherclass"></div>
干杯,伙计们。
I would like to remove a div from the TinyMCE editor content that has a specific class.
In the ideal world I'd like to be able to do this via the valid_elements option but I don't know if it's achievable.
Here is a sample of editor content:
<div class="content">
Some html content here
<div class="anotherclass"></div>
</div>
I would like the
<div class="content">
stripping out so the editor will only show this:
Some html content here
<div class="anotherclass"></div>
Cheers guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先获取 div 的innerHTML,然后将该内容附加到 div,然后可以将其删除。
在 jQuery 中:
当然,如果你有多个带有这些类的 div,那就更复杂了,因为那样你就必须与父母等一起工作。
First get the innerHTML of the div, and then append that content to the div, after which you can remove it.
In jQuery:
Of course, if you have multiple divs with these classes its more complicated because then you would have to work with parents etc.
这里的问题是,默认情况下,您的编辑器将有一个 root_block 元素(在您的例子中为 div),并且所有内容都包含在这种 root_block 元素中。这样做是为了样式目的,但可以使用此初始化参数来停用。
完成后,您可以使用此代码轻松摆脱您的 div。
Problem here will that by default your editor will have a root_block element (in your case div) and all content gets wrapped inside that kind of root_block element. This is done for styling purposes, but can be deactivated using this initialization params
Once that is done you can use this code to easily get rid tof your divs.