Javascript encodeURIComponent doesn't encode single quotes

后端 未结 6 1477
刺人心
刺人心 2021-02-01 03:39

Try it out:

encodeURIComponent(\"\'@#$%^&\");

If you try this out you will see all the special characters are encoded except for the single

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 04:10

    I'm not sure why you would want them to be encoded. If you only want to escape single quotes, you could use .replace(/'/g, "%27"). However, good references are:

    • When are you supposed to use escape instead of encodeURI / encodeURIComponent?
    • Comparing escape(), encodeURI(), and encodeURIComponent() at xkr.us
    • Javascript Madness: Query String Parsing #Javascript Encode/Decode Functions

提交回复
热议问题