admin管理员组

文章数量:1414881

i want to encode this text from

2016, Odd Semester, Periode 1

to

2016%2C%20Odd%20Semester%2C%20Periode%201

but i can't encode the ma.

it show like this

2016,%20Odd%20Semester,%20Periode%201

here my code

var Term = '2016, Odd Semester, Periode 1'
encodeURI(Term);

i want to encode this text from

2016, Odd Semester, Periode 1

to

2016%2C%20Odd%20Semester%2C%20Periode%201

but i can't encode the ma.

it show like this

2016,%20Odd%20Semester,%20Periode%201

here my code

var Term = '2016, Odd Semester, Periode 1'
encodeURI(Term);
Share Improve this question asked Nov 22, 2016 at 8:59 KentgiKentgi 3181 gold badge4 silver badges15 bronze badges 4
  • 4 use encodeURIComponent – Semi-Friends Commented Nov 22, 2016 at 9:00
  • 2 or use encodeURIComponent instead – Thum Choon Tat Commented Nov 22, 2016 at 9:00
  • 2 This function encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters). – Kevin Kloet Commented Nov 22, 2016 at 9:01
  • related post: stackoverflow./q/18251399/6908282 – Gangula Commented Nov 12, 2024 at 18:20
Add a ment  | 

2 Answers 2

Reset to default 5

Use encodeURIComponent():

var foo = encodeURIComponent('2016, Odd Semester, Periode 1');
console.log(foo);

Use encodeURIComponent(). It should suffice.

The encodeURIComponent() function encodes special characters. In addition, it encodes the following characters:

, / ? : @ & = + $ #

var Term = '2016, Odd Semester, Periode 1'
encodeURIComponent(Term);

本文标签: jqueryjavascript comma doesn39t encodedStack Overflow