jQuery javascript regex Replace
with \n

前端 未结 5 554
独厮守ぢ
独厮守ぢ 2020-12-02 11:46

How do i write a regex to replace
or
with \\n. I\'m trying to move text from div to textarea, but don\'t want

5条回答
  •  不知归路
    2020-12-02 12:44

    a cheap and nasty would be:

    jQuery("#myDiv").html().replace("
    ", "\n").replace("
    ", "\n")

    EDIT

    jQuery("#myTextArea").val(
        jQuery("#myDiv").html()
            .replace(/\/g, "\n")
            .replace(/\
    /g, "\n") );

    Also created a jsfiddle if needed: http://jsfiddle.net/2D3xx/

提交回复
热议问题