简体   繁体   English

如何保存/添加所有特殊字符,如(“&')ETC

[英]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 与逃生

Here 这里

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);

And here's your fiddle 这是你的小提琴

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

相关问题 在 php 上创建 A-Z 索引列表时,如何将所有特殊字符和数字(. , . 1 2 3 4 5 等?)放在# 符号下? - How to put all the special characters and numbers like ( . , ! 1 2 3 4 5 etc. ) under # symbol when creating an A - Z index listing on php? 如何使用JavaScript在XML文件中添加特殊字符,如&&gt; - How to add special characters like & > in XML file using JavaScript html5数据库将&#39;?!&等另存为html5数据库中的特殊字符 - html5 database save '?!& etc as special characters in the html5 database 如何匹配所有语言字符(如英语,希腊语,中文)(特殊字符除外) - how to match all language characters like english, greek, chinese except the special characters 如何在Lodash中使用特殊字符(如&#39;&&#39;)格式化字符串? - How to format strings with special characters like '&' in Lodash? PHP / jQuery提交/保存具有所有特殊字符值的输入 - PHP/jQuery to submit/save input with all special characters value 如何在JavaScript中转义“,&lt;和所有特殊字符 - How to escape ",< and all special characters in JavaScript 如何用空格替换字符串中的所有特殊字符 - How to replace all special characters in a string with space 如何匹配除逗号以外的所有特殊字符 - how to match all special characters except a comma 如何防止表格中的所有特殊字符 - How to prevent all special characters in a form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM