Convert HTML to plain text in contentEditable

后端 未结 4 1941
忘了有多久
忘了有多久 2021-02-07 07:10

I have a contentEditable and I strip the formatting of pasted content on(\'paste\') by catching the event. Then I focus a textarea, paste the content i

4条回答
  •  故里飘歌
    2021-02-07 08:09

    Upon request from Jonathan Hobbs I am posting this as the answer. Thanks to the answers above I modified my code and solved the issue. I basically copied the value of textarea into a div and grabbed only its .text():

    // on paste, strip clipboard from HTML tags if any
    $('#post_title, #post_content').on("paste", function() {
      setTimeout(function(){
        var text = $('
    ').html($("#area").val()).text(); pasteHtmlAtCaret(text); }, 20); });

提交回复
热议问题