inyfee
V2EX  ›  问与答

jquery text() 方法,能否保留空格和换行符?

  •  
  •   inyfee · Jan 30, 2013 · 15059 views
    This topic created in 5005 days ago, the information mentioned may be changed or developed.
    我有个 div contenteditable ,监听paste 事件 ,把取得的粘贴内容 ,用jquery text() 方法 添加进去,但是会发现原内容的所有空格和换行符都被扔掉了,我想保留空格和换行符,请问该如何做?
    本来用 html() 也可以,但是如果我的内容是html 代码块,就不行了。
    1 replies  •  1970-01-01 08:00:00 +08:00
    qiayue
        1
    qiayue  
       Jan 30, 2013
    字符串替换,\r\n转成<br />
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2668 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:50 · PVG 23:50 · LAX 08:50 · JFK 11:50
    ♥ Do have faith in what you're doing.