javascript 如何在 jQuery 中编码特殊字符 (>,<,%)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10771374/
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
How to encode special characters (>,<,%) in jQuery
提问by user472625
Can anyone give me a sample script to encode special characters (>,<,%) in jQuery?
谁能给我一个示例脚本来在 jQuery 中编码特殊字符(>、<、%)?
回答by Amarok
escape(string)
is a deprecated function.
escape(string)
是一个不推荐使用的函数。
You can use encodeURI(string)
for URL-safe strings and encodeURIComponent(string)
to escape other characters as well: , / ? : @ & = + $ #
您可以使用encodeURI(string)
URL 安全字符串并encodeURIComponent(string)
转义其他字符: , / ? : @ & = + $ #
encodeURI("<>?")
returns "%3C%3E?"
encodeURI("<>?")
回报 "%3C%3E?"
encodeURIComponent("<>?")
returns "%3C%3E%3F"
encodeURIComponent("<>?")
回报 "%3C%3E%3F"
回答by dda
escape("how to encode special characters(>,<,%) in jQuery")
"how%20to%20encode%20special%20characters%28%3E%2C%3C%2C%25%29%20in%20jQuery"