inyfee
V2EX  ›  问与答

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

  •  
  •   inyfee · Jan 30, 2013 · 14866 views
    This topic created in 4878 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  
    PRO
       Jan 30, 2013
    字符串替换,\r\n转成<br />
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4073 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 04:13 · PVG 12:13 · LAX 21:13 · JFK 00:13
    ♥ Do have faith in what you're doing.