最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - javascript comma doesn't encoded - Stack Overflow

programmeradmin1浏览0评论

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);
发布评论

评论列表(0)

  1. 暂无评论