[英]How to save / add all special characters like ( " & ' ) ETC
Special Characters 特殊的角色
! @ # $ % ^ & * ( ) _ + = - { [ } ] : ; " ' | \\ < , > . ? /
I have a simple saving of data. 我有一个简单的数据保存方式。 I notice that if I enter all special characters in a textbox and not using a escape
method all special character after the &
sign is being cut. 我注意到,如果我在文本框中输入所有特殊字符,并且未使用escape
方法,则&
符号被剪切后,所有特殊字符都会被删除。
With Out Escpae 没有了Escpae
Output 输出量
! @ # $ % ^
With Escape 与逃生
JS JS
var txt = $("txtbox").val();
Notice that the output has a %20%
how I remove it?. 请注意,输出中有%20%
如何删除它?
%20
is space. %20
是空格。 If you wish to remove it, you can do it like, 如果您希望删除它,可以按照以下方式进行操作:
Note that escape
is deprecated, Use encodeURIComponent
instead. 请注意, escape
已被弃用,请改用encodeURIComponent
。
var str = `! @ # $ % ^ & * ( ) _ + = - { [ } ] : ; " ' | \ < , > . ? /`;
var encoded = encodeURIComponent(str.split(' ').join(''));
// or encodeURIComponent(str.replace(/\s+/g, ''));
alert(encoded);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.