是否可以使用JavaScript / jQuery进行36编码?

编程入门 行业动态 更新时间:2024-10-25 14:35:56
本文介绍了是否可以使用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编码?

本文发布于:2023-11-30 14:53:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   JavaScript   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!