是否可以使用JavaScript / jQuery进行36编码? [英] Is it possible to base 36 encode with JavaScript / jQuery?
本文介绍了是否可以使用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)
想要跟踪用户推荐,邀请网址。我可以使用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编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文