V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
inyfee
V2EX  ›  问与答

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

  •  
  •   inyfee · Jan 30, 2013 · 14806 views
    This topic created in 4845 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   ·   5822 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:40 · PVG 14:40 · LAX 23:40 · JFK 02:40
    ♥ Do have faith in what you're doing.