使用 jQuery/JavaScript 删除转义字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12508706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:23:10  来源:igfitidea点击:

Remove escape characters string using jQuery/JavaScript

javascriptjquery

提问by Arjunan Arjun

I want to remove the escape charecters from a string using jquery.

我想使用 jquery 从字符串中删除转义字符。

I know about the "escape()" in jquery but the issue is

我知道 jquery 中的“escape()”,但问题是

For example I want to remove the escape charecters from the string "http://www.abc.com" if we

例如,我想从字符串“http://www.abc.com”中删除转义字符,如果我们

use escape() we get the result like this 'http%3A//www.abc.com' but i want the result like

使用 escape() 我们得到这样的结果 'http%3A//www.abc.com' 但我想要这样的结果

'http//www.abc.com'. How it possible using jquery?

'http//www.abc.com'。怎么可能使用jquery?

采纳答案by Michael Schmidt

escape()encodes the special characters! To remove the characters, use for example replaceAll(String regex, String replacement).

escape()对特殊字符进行编码!要删除字符,请使用例如replaceAll(String regex, String replacement)

In the regex-part you can insert all of the special character you want to remove.

regex-part 中,您可以插入所有要删除的特殊字符。

回答by Jashwant

There's nothing in jQuery about unescpaing.

jQuery 中没有任何关于 unescpaing 的内容。

Core javascript has escape()and unescape()function.

核心javascript有escape()unescape()函数。

var url = 'http://www.abc.com';

var escaped_url = escape(url);

console.log(escaped_url); // logs 'http%3A//www.abc.com'

console.log(unescape(escpaed_url)) // logs 'http://www.abc.com'

i.e.

IE

unescape(escape('http://www.abc.com')) === 'http://www.abc.com'

unescape(escape('http://www.abc.com')) === 'http://www.abc.com'

回答by CR41G14

Use a regex? replace(/[^a-z0-9\s]/gi, '')function? Amend to characters you want to keep

使用正则表达式?replace(/[^a-z0-9\s]/gi, '')功能?修改您要保留的字符