gpt4 book ai didi

javascript - 在 Jquery 中执行 replaceWith 时,文本在特殊字符后被 chop

转载 作者:行者123 更新时间:2023-11-30 15:54:45 25 4
gpt4 key购买 nike

我正在将文本输入文本区域,这将是来自用户的注释。字符串看起来像这样。如果其中有特殊字符,一些文本会被 javascript 中的替换调用 chop 。

这是正文。

This "email" and any files transmitted with it are proprietary and ?><??><intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. Please note that any views or opinions presented in this email :"":&((*)((*)(*)( are solely those of the author and do not necessarily represent those of the company.

这是我在 Javascript 中所做的。 'newNote' 是我的文本区域

$(newNote).replaceWith("<div name=\"note\" class=\"contractNote\">" + "<span style=\"white-space: pre-line\">" + $(newNote).val() + "</span></div>");

这是我之后在页面上看到的内容。特殊字符被砍掉后,一切看起来都是一样的。

This "email" and any files transmitted with it are proprietary and ?>

最佳答案

https://jsfiddle.net/nnmfe7L2/1/

<??><intended ....被视为标签而不被渲染

这是一个纯HTML问题

对所有 < 进行字符串替换至 &lt;在将字符串插入 DOM 之前

$('#note').replaceWith("<div name=\"note\" class=\"contractNote\"><span style=\"white-space: pre-line\">" +
text.replace(/</g,"&lt;") +
"</span></div>");

关于javascript - 在 Jquery 中执行 replaceWith 时,文本在特殊字符后被 chop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38752176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com