• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
JS小灰童鞋
博客园    首页    新随笔    联系   管理    订阅  订阅
2016年1月27日
10进制转2进制
摘要: <script> function dec(num) { if (isNaN(num)) return; return parseInt(num, 10).toString(2); } console.log(dec("10")); </script> 阅读全文
posted @ 2016-01-27 15:55 JS小灰童鞋 阅读(158) 评论(0) 推荐(0)
计算字符串中出现次数最多的字符及个数
摘要: <script> function infinity(str) { var arr = str.split("") .sort() .join("") .replace(/((.)\2*)/g, "$1,") .split(",") .sort(function(a, b) { return b.l 阅读全文
posted @ 2016-01-27 15:41 JS小灰童鞋 阅读(186) 评论(0) 推荐(0)
二分法求数组中某个数出现的位置索引
摘要: <script> function twoIndex(val, arr) { var start = 0, end = arr.length - 1, middle = Math.floor((start + end) / 2); while (arr[middle] !== val && end 阅读全文
posted @ 2016-01-27 15:37 JS小灰童鞋 阅读(347) 评论(0) 推荐(0)
数字添加逗号即千分号
摘要: <script> /* 正则 */ function addComma(num) { return !isNaN(num) && num.replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, "$1,"); } console.log(addComma("1234567 阅读全文
posted @ 2016-01-27 15:29 JS小灰童鞋 阅读(1109) 评论(0) 推荐(0)
仿支付宝金额输入规则
摘要: <!-- 正则 --> <body> <input type="text" id="pay"> <script> document.getElementById("pay").addEventListener("input", function() { this.value = this.value 阅读全文
posted @ 2016-01-27 14:49 JS小灰童鞋 阅读(717) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3