简体   繁体   English

如何从Textaea中删除所有锚点+锚文本?

[英]How can I remove all anchor + anchor text from a Textaea?

I'm getting something like this in a textarea: 我在textarea中得到这样的东西:

`Some text <a href="">Click me!</a>`

how can I remove all chars included Click me! 如何删除所有包含的字符Click me! from < to > using javascript replace method or using something similar? < to >使用javascript replace方法或使用类似的东西?

var ta = document.getElementById('id-of-textarea');
ta.value = ta.value.replace(/<a(|\s[^>]*)>[\s\S]*?<\/a>/gi, '');

will cover the most likely cases. 将涵盖最可能的案件。 You probably shouldn't generalize this to a more complex situation though. 您可能不应该将其概括为更复杂的情况。

This does not replace the need to sanitize your input on the server side. 这并不能取代在服务器端清理输入需要 In fact, the above should probably be done on the server side if at all possible, and a JavaScript approach (probably ignored by the spam bots anyways) used only if, say, this is off-the-shelf blogging software and you cannot modify it. 事实上,如果可能的话,上面应该可以在服务器端完成,并且只有当这是现成的博客软件并且你无法修改时,使用JavaScript方法(可能被垃圾邮件机器人忽略)。它。

you can check this google caja plugin to sanitize the input. 你可以检查这个谷歌caja插件来消毒输入。 BUT! 但! you MUST sanitize your input on the server side too. 你必须在服务器端清理你的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM