contentEditable field to maintain newlines upon database entry

前端 未结 3 1562
深忆病人
深忆病人 2020-12-29 08:41

I have a div with the attribute contentEditable set.

This allows me to have a free-form editable textarea, without the need for any form input fields: http://jsfiddl

3条回答
  •  鱼传尺愫
    2020-12-29 08:50

    function readContentWithBreaks(elem){
      if(elem[0].innerText){
        return elem[0].innerText.replace(/\n/ig,"
    "); }else{ return elem.html(); } }

    Since webkit browsers support innerText I decided to detect for that swap the /n they add. For Firefox it already gives the content with
    so we can just take it as-is.

提交回复
热议问题