有没有一种方法可以使用jQuery。在可满足的文本位置上贴上?

发布于 2025-01-22 08:15:29 字数 1825 浏览 2 评论 0原文

就像标题所述的那样,是否有一种使用jQuery的方法。在可满足的Div,选定的文本位置上应用?我可以在该位置插入HTML的可满足插件。但是我需要jQuery .Append函数。

干杯!

var ffclickcount = 0;
  $('#fff').click(function(e) {
    ffclickcount = ffclickcount + 1;
    var newfff = '<br/><form> <textarea id="ItemNEW' + ffclickcount + '"></textarea> </form><br/>';
    $("#Ntext").append(newfff);
    
  });
  
  // IN MY OWN CODE I HAVE THIS ALSO INSIDE THE VAR NEWFFF BUT THAT GIVES A ERROR ON SO SNIPPET //
 // <script> var editor = CodeMirror.fromTextArea(document.getElementById("ItemNEW'+ffclickcount+'"), { mode: "text/html", theme: "eclipse", lineWrapping: true, styleActiveLine: true, matchBrackets: true, readOnly: false }); var charWidth = editor.defaultCharWidth(), basePadding = 4; editor.on("renderLine", function(cm, line, elt) { var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth; elt.style.textIndent = "-" + off + "px"; elt.style.paddingLeft = (basePadding + off) + "px"; }); editor.refresh(); </script>
.SWItextar {
    width:100%;
    max-width:100%;
    height:50vh;
    min-height:50vh;
    margin-top:1vh;
    margin-bottom:1vh;
    border-top:1px solid #eee;
    border-bottom:1px solid #eee;
    resize: vertical;
    overflow-x: auto;
    outline:none;
    cursor: text;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<span id="fff">click insert form</span>
<div name="text" id="Ntext" class="SWItextar" contenteditable="true" autofocus></div>

Like the title say's, Is there a way to use jQuery .append on contenteditable div, selected text position? I can find a lot for the contenteditable insert html at that position. But I need the jQuery .append function.

Cheers!

var ffclickcount = 0;
  $('#fff').click(function(e) {
    ffclickcount = ffclickcount + 1;
    var newfff = '<br/><form> <textarea id="ItemNEW' + ffclickcount + '"></textarea> </form><br/>';
    $("#Ntext").append(newfff);
    
  });
  
  // IN MY OWN CODE I HAVE THIS ALSO INSIDE THE VAR NEWFFF BUT THAT GIVES A ERROR ON SO SNIPPET //
 // <script> var editor = CodeMirror.fromTextArea(document.getElementById("ItemNEW'+ffclickcount+'"), { mode: "text/html", theme: "eclipse", lineWrapping: true, styleActiveLine: true, matchBrackets: true, readOnly: false }); var charWidth = editor.defaultCharWidth(), basePadding = 4; editor.on("renderLine", function(cm, line, elt) { var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth; elt.style.textIndent = "-" + off + "px"; elt.style.paddingLeft = (basePadding + off) + "px"; }); editor.refresh(); </script>
.SWItextar {
    width:100%;
    max-width:100%;
    height:50vh;
    min-height:50vh;
    margin-top:1vh;
    margin-bottom:1vh;
    border-top:1px solid #eee;
    border-bottom:1px solid #eee;
    resize: vertical;
    overflow-x: auto;
    outline:none;
    cursor: text;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<span id="fff">click insert form</span>
<div name="text" id="Ntext" class="SWItextar" contenteditable="true" autofocus></div>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文