简体   繁体   English

如何保持textarea中的文本格式相同

[英]How to keep the text format same from in textarea

I am inserting some text using textarea. 我正在使用textarea插入一些文本。 I want to substring the textarea once it reaches the limit and set the content to the same editor. 我想在textarea达到限制时对其进行子串,并将内容设置为相同的编辑器。 But its removing the formatting before whatever is texted and setting plain text. 但它删除格式化之前发短信和设置纯文本。 I want with same format. 我想要相同的格式。

  tinyMCE.init({ mode: "textareas", theme: "advanced", editor_selector: "mceEditor", paste_auto_cleanup_on_paste: 'true', theme_advanced_disable: 'justifyleft,justifyright,justifyfull,justifycenter,indent,image,anchor,sub,sup,unlink,outdent,help,removeformat,link,fontselect,hr,styleselect,formatselect,charmap,separator,code,visualaid,strikethrough,fullscreen', theme_advanced_buttons1: 'bold,italic,underline,numlist,bullist,undo,redo,cleanup,spellchecker', theme_advanced_buttons2: "", theme_advanced_buttons3: "", plugins: 'spellchecker,fullscreen,paste', spellchecker_languages: '+English=en-us', spellchecker_rpc_url: '<%out.print(request.getContextPath());%>/jazzy-spellchecker', theme_advanced_statusbar_location: "bottom", theme_advanced_path: false, statusbar: true, setup: function (editor) { editor.onKeyUp.add(function (evt) { var inputRichTextArea = $(editor.getBody()).text(); var maxLengthRichTextArea = document.getElementById(editor.id).maxLength; var inputRichTextAreaLength = inputRichTextArea.length; if (inputRichTextAreaLength > maxLengthRichTextArea) { inputRichTextAreaLength = maxLengthRichTextArea; editor.setContent(""); tinyMCE.activeEditor.selection.setContent(inputRichTextArea.substring(0, maxLengthRichTextArea)); } var value = maxLengthRichTextArea - inputRichTextAreaLength; if (value >= 0) { $(editor.getContainer()).find("#" + editor.id + "_path_row").html("Remaining characters: " + (value)); } if (inputRichTextAreaLength >= maxLengthRichTextArea) { $(editor.getBody()).keypress(function (e) { inputRichTextAreaLength = $(editor.getBody()).text().length; if (inputRichTextAreaLength >= maxLengthRichTextArea) { e.stopPropagation(); return false; } var value = maxLengthRichTextArea - inputRichTextAreaLength; if (value >= 0) { $(tinyMCE.activeEditor.getContainer()).find("#" + editor.id + "_path_row").html("Remaining characters: " + (value)); } }); } }); } }); 
 <textarea maxlength = 50 rows="4" cols="50"></textarea 

How can I keep the same formatting. 如何保持相同的格式。

Pasting text 粘贴文字

Formatting text 格式化文本

In your example, you use the function .text() to get the content which only selects the text without format. 在您的示例中,您使用函数.text()来获取仅选择没有格式的文本的内容。 Try using .getContent() instead, as it selects the whole content. 请尝试使用.getContent() ,因为它会选择整个内容。

There are already question and answers about it here on StackOverflow . StackOverflow上已有问题和答案。 Please follow the instructions there. 请按照那里的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM