在 CKEditor 中提取粘贴 html 的部分内容

发布于 2024-09-07 10:10:21 字数 1281 浏览 1 评论 0原文

我正在将 CKEditor 用于我的 asp.net mvc (C#) 应用程序。

我需要在粘贴到 CKEditor 之前提取 html 的一部分。

例如,我有以下 html 准备好粘贴到 CKEditor:

<html>
<body>
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                Dummy Content
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%" border="0" id="tabletocopy" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            Actual Content
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>

我只需要复制表“tabletocopy”的 html,而不是整个(包括正文)html,例如:

<table width="100%" border="0" id="tabletocopy" cellpadding="0" cellspacing="0">
   <tr>
      <td>
         Actual Content
      </td>
   </tr>
</table>

我发现CKEditor 的 粘贴事件,但我不是确定如何使用它来满足我的需要。

对此有什么想法吗?

I am using CKEditor for my asp.net mvc (C#) application.

I need to extract a part of html before pasting to the CKEditor.

For Ex, i have the following html ready to be pasted to CKEditor:

<html>
<body>
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                Dummy Content
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%" border="0" id="tabletocopy" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            Actual Content
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>

I need to copy only the html of the table "tabletocopy", not the entire(including body) html, something like:

<table width="100%" border="0" id="tabletocopy" cellpadding="0" cellspacing="0">
   <tr>
      <td>
         Actual Content
      </td>
   </tr>
</table>

I found the paste event of CKEditor, but i am not sure on how to use this for my need.

Any ideas on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舞袖。长 2024-09-14 10:10:21

在粘贴事件中,您将在 e.data.html 中获取 html,如 链接

在这种情况下,您可以使用 jquery 提取 html。

e.data.html = $(e.data.html).find("#tabletocopy").html();

On paste event, you will get the html in e.data.html as described in link.

In that event you can extract the html using jquery.

e.data.html = $(e.data.html).find("#tabletocopy").html();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文