如何使用 Javascript 或使用 JQuery 的帮助从所见即所得中获取价值?

发布于 2025-01-19 18:06:55 字数 1917 浏览 4 评论 0 原文

我想问。我想创建一个博客,但使用了Microsoft Word风格的文本编辑器。如果假设使用香草JavaScript或纯JavaScript或使用jQuery的帮助?

我的代码:

<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
    <!-- CDN WYSIWYG (TINYMICE) -->
    <script src="https://cdn.tiny.cloud/1/fjxlmvgx0f36t65lwkpdwdyrxxahi85ni9wp3e2xp17gjitr/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>
</head>
<body>
    <!-- Text-Area -->
    <textarea id="my_text"></textarea>
    <!-- Button Get Value -->
    <button id="value_button">Get Value</button>

    <script>
        // Install WYSIWYS (TINYMICE)
        tinymce.init({
            selector: 'textarea',
            plugins: 'a11ychecker advcode casechange export formatpainter image editimage linkchecker autolink lists checklist media mediaembed pageembed permanentpen powerpaste table advtable tableofcontents tinycomments tinymcespellchecker',
            toolbar: 'a11ycheck addcomment showcomments casechange checklist code export formatpainter image editimage pageembed permanentpen table tableofcontents',
            toolbar_mode: 'floating',
            tinycomments_mode: 'embedded',
            tinycomments_author: 'Author name',
          });

        // Dom (get id:my_text & value_button)
        let my_text = document.getElementById("my_text");
        let value_button = document.getElementById("value_button");

        // get value in console
        value_button.addEventListener("click",()=>{
            console.log(my_text.value)
        })
      </script>

我想先获取值。就像想写“星期四”一样

,出现的是 “ &lt; p&gt;星期四&lt;/p&gt;

我的障碍,我输入了任何值是“”(空)

注:我的wysiwyg是tinymice

,但是,但是如果您有另一种类型的Wysiwyg,我将尝试 谢谢

I want to ask. I wanted to create a blog, but used a Microsoft word-style text editor. If suppose using vanilla javascript or pure javascript or using the help of JQuery?

MY code:

<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
    <!-- CDN WYSIWYG (TINYMICE) -->
    <script src="https://cdn.tiny.cloud/1/fjxlmvgx0f36t65lwkpdwdyrxxahi85ni9wp3e2xp17gjitr/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>
</head>
<body>
    <!-- Text-Area -->
    <textarea id="my_text"></textarea>
    <!-- Button Get Value -->
    <button id="value_button">Get Value</button>

    <script>
        // Install WYSIWYS (TINYMICE)
        tinymce.init({
            selector: 'textarea',
            plugins: 'a11ychecker advcode casechange export formatpainter image editimage linkchecker autolink lists checklist media mediaembed pageembed permanentpen powerpaste table advtable tableofcontents tinycomments tinymcespellchecker',
            toolbar: 'a11ycheck addcomment showcomments casechange checklist code export formatpainter image editimage pageembed permanentpen table tableofcontents',
            toolbar_mode: 'floating',
            tinycomments_mode: 'embedded',
            tinycomments_author: 'Author name',
          });

        // Dom (get id:my_text & value_button)
        let my_text = document.getElementById("my_text");
        let value_button = document.getElementById("value_button");

        // get value in console
        value_button.addEventListener("click",()=>{
            console.log(my_text.value)
        })
      </script>

I want to get the value first. Like wanting to write "Thursday"

Perhaps, what appears is
"<p>Thursday</p>"

My obstacle, I typed whatever the value is ""(empty)

Note: My WYSIWYG is TinyMice

However, if you have another type of WYSIWYG, I will try it
Thankyou

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

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

发布评论

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

评论(1

浮世清欢 2025-01-26 18:06:55

TinyMCE 有一个 API 来获取其当前内容:

getContent() - https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#getcontent

对于一些背景,当您加载 TinyMCE 时,它会覆盖您的textarea 带有 iframe,因此当您在 TinyMCE 中输入内容时,您不会更新 textarea

话虽这么说,有一个 API 调用可以使 TinyMCE 将其当前内容推回到 textarea 中:

triggerSave() - https://www.tiny.cloud/docs/api/tinymce/root_tinymce/#triggersave

...因此,如果您需要专门使用 textarea 执行某些操作,您可以首先调用 triggerSave()

TinyMCE has an API to get its current content:

getContent() - https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#getcontent

For some background, when you load TinyMCE it overlays your textarea with an iframe so when you are typing into TinyMCE you are not updating the textarea.

That being said, there is an API call to make TinyMCE push its current content back into the textarea:

triggerSave() - https://www.tiny.cloud/docs/api/tinymce/root_tinymce/#triggersave

...so if you need to do something specifically with the textarea you can call triggerSave() first.

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