本文介绍了是否可以使用JavaScript / jQuery进行36编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在考虑在这里使用编码/解码技术(编码到基础36 /从基础36解码在Ruby中很简单)
I'm thinking about using the encode/decode technique here (Encoding to base 36/decoding from base 36 is simple in Ruby)
如何在Twitter上实现像网址一样的简短网址?
想要跟踪用户推荐,邀请网址。我可以使用Rails进行解码,但有没有办法用Javascript或jQuery编码?
Idea being to track user referrals, invite URLs. I can use Rails to decode, but it there a way to encode with Javascript or jQuery?
推荐答案toString 上的方法有一个可选参数radix:
The toString method on Number has an optional argument of radix:
(128482).toString(36); 128482..toString(36); 128482 .toString(36); var num = 128482; num.toString(36);注意这不起作用,因为数字期望一段时间后的十进制数字,而不是字母:
Note this doesn't work, because numbers expect decimal digits after a period, not letters:
128482.toString(36); // Syntax error此外,你也可以用JS解码:
Also, you can decode with JS as well:
parseInt("2r4y", 36);更多推荐
是否可以使用JavaScript / jQuery进行36编码?
发布评论