在结束... Javascript不会替换'\\\<br/>'! [英] At witt&#39;s end... Javascript won&#39;t replace &#39;\n&#39;!

查看:101
本文介绍了在结束... Javascript不会替换'\\\<br/>'!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这个问题上坚持了几个小时,没有运气。不知道这是甚么可能的;我将尝试总结。

I've been going at this problem for a solid couple hours now and having zero luck. No clue how this is even possible; I'll try to summarize.

我正在使用TinyMCE将新内容插入数据库,该内容在插入到AJAX响应后作为AJAX响应发送回DB然后显示在页面上,替换一些旧内容。所有这一切都不是真正的关联(据我所知),这个问题,但它作为一个背景的问题。

I'm using TinyMCE to insert new content to a DB, that content is being sent back as an AJAX response after it is inserted into the DB and then shown on the page, replacing some old content. All of that isn't really relevant (as far as I can tell) to the problem, but it serves as a background to the problem.

无论如何,响应文本无论内容是否有换行符都适用。我似乎无法消除那些我生命中死亡的人。我试过十几个正则表达式/替换组合与零运气。我已经验证我没有失去我的想法,代码通常是通过尝试替换字符串中的其他单词,并且工作完美 - 它不会替换'\\\
'。以下是我尝试替换'\'的代码:

Anyhow, the response text has '\n' appropriately wherever the content had line breaks. I can't seem to remove those damn '\n' for the life of me. I've tried a dozen regex/replace combos with zero luck. I've verified I am not losing my mind and that the code generally works by attempting to replace other words within that string and that works perfectly fine - it just will NOT replace '\n'. Here's some code I've used attempting to replace the '\n's:


responseText = responseText.replace(/ \r | \\ \\ n | \r\\\
/ g,);

responseText = responseText.replace(/\r|\n|\r\n/g, "");

responseText = responseText.replace(Array(\r,\\\
,\f,\\\\
,\\\
),);

responseText = responseText.replace(Array("\r", "\n", "\f", "\r\n", "\n"), "");

Niether那些对变量做任何事情。我立即提醒它,以检查变化,纳达。我不知道这是否会有所帮助,但这里是一个例子'\''复制粘贴的代码片段,不会消失或改变。<​​/ p>

Niether of those do anything to the variable. I alert it immediately after to check for changes, nada. I have no idea if it will help, but here's a snippet of an example '\n' copy-pasted that will not disappear OR change.

High School transcript</li>\n<li>SAT/ACT

作为附注,我已经尝试通过PHP进行此操作,然后将responseText发送回javascript,并使用类似的替换&正则表达式,它也不起作用。

As a side note, I've tried doing this via PHP before the responseText is sent back to javascript with a similar replace & regex and it does NOT work either.

推荐答案

你确定这是一个换行符,而不是字面上的\\\
是一个转义的换行符)?

Are you sure it's a newline and not a literal "\n" (that is an escaped newline) ?

改为:(注意双反斜杠)

Try this instead: (note the double backslash)

responseText = responseText.replace(/\\n/g, "");

这篇关于在结束... Javascript不会替换'\\\<br/>'!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆