为什么我无法编辑附加的文本区域

Why can't I edit an appended textarea?

本文关键字:文本 区域 编辑 为什么      更新时间:2023-09-26

我正在尝试将文本区域附加到div。 附加文本区域后,在调整浏览器窗口大小之前,我无法选择它开始键入。 如何使其在第一次时可选?

<script>
$("#distraction-mode").click(function(e){ // Entering the distraction mode
        e.preventDefault();
    $("#wysiwyg").appendTo("#wysiwyg-fullscreen");
});
</script>
<div id="wysiwyg-fullscreen-container">
    <div id="wysiwyg-fullscreen"></div> <!-- div where textarea will be -->
</div>
<div id="wysiwyg">
    <textarea id="editor" name="editor" rows="" cols=""></textarea>
    <a href="#" id="distraction-mode">Distraction Mode</a>
</div>

一个猜测,但你可以在文本区域调用.refresh(),然后.focus()

这是基于此处的文档

编辑
您需要将编辑器设置为变量,以便您可以访问它并能够专门调用其上的函数。在将它附加到另一个元素后使用 refresh()focus() 有望允许它调整大小和重置自身。

它可能看起来像这样:

<script>
var editor = $("#editor").cleditor()[0];
$("#distraction-mode").click(function(e){
  // Entering the distraction mode
  e.preventDefault();
  $("#wysiwyg").appendTo("#wysiwyg-fullscreen");
  editor.refresh();
  editor.focus();
});
</script>