随笔分类 - JavaScript工具类
一些常用的JavaScript工具类
摘要:原数据: 结果: var arr = [ { "label": "00:00-00:15", "count": 3 }, { "label": "00:15-00:30", "count": 3 }, { "label": "12:00-12:15", "count": 3 }, { "label"
阅读全文
摘要:结果 var data = [ { "key": "sub1", "children": [ { "key": "sub1-1" } ] }, { "key": "sub2", "children": [ { "key": "sub2-1", "children": [ { "key": "sub2
阅读全文
摘要:const arr = [ {id: "1", en: "Afghanistan", cn: "阿富汗", code: "93"}, {id: "2", en: "Iraq", cn: "伊拉克", code: "964"}, {id: "3", en: "Qatar", cn: "卡塔尔", co
阅读全文
摘要:// iframe自适应高度 $(window).bind("load resize", function() { topOffset = 50; width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.
阅读全文
摘要:获取ID /** * * @param {*} id 获取ID * @returns */ function $(id){ return typeof id 'string'?document.getElementById(id):null; } // 使用方法 console.log($('tex
阅读全文
摘要:// 经纬度转换成三角函数中度分表形式。 function rad(d) { return d * Math.PI / 180.0; } // 根据经纬度计算距离,参数分别为第一点的纬度,经度;第二点的纬度,经度 function getDistance(lat1, lng1, lat2, lng2
阅读全文
摘要:(function (window) { // *****fomr表单提交解决地址栏过长**********************************************************************************************************
阅读全文
摘要:结果: /** * * @param {*} formater 时间格式 * @param {*} time 自定时间,默认当前时间 * @returns */ const dateFormater = (formater, time) => { let date = time ? new Date
阅读全文
摘要:结果: const nowTime = () => { const now = new Date(); const year = now.getFullYear(); const month = now.getMonth(); const date = now.getDate() >= 10 ? n
阅读全文
摘要:const getExplorerInfo = () => { let t = navigator.userAgent.toLowerCase(); return 0 <= t.indexOf("msie") ? { //ie < 11 type: "IE", version: Number(t.m
阅读全文
摘要:const broswer = () => { const ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "micromessenger") { return "weixin"; } else i
阅读全文
摘要:结果: /** * * @param {*} value 身份证 * @returns */ const checkCardNo = (value) => { let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; return reg.test(
阅读全文
摘要:结果: /** * * @param {*} value 数字 * @returns */ const intToChinese = (value) => { const str = String(value); const len = str.length-1; const idxs = ['',
阅读全文
摘要:结果: /** * * @param {*} n 数字 * @returns */ const digitUppercase = (n) => { const fraction = ['角', '分']; const digit = [ '零', '壹', '贰', '叁', '肆', '伍', '
阅读全文
摘要:结果: /** * * @param {*} tel 电话号码 * @returns */ const telFormat = (tel) => { tel = String(tel); return tel.substr(0,3) + "****" + tel.substr(7); }; cons
阅读全文
摘要:结果: /** * * @param {*} str 字符串 * @returns */ const fistLetterUpper = (str) => { return str.charAt(0).toUpperCase() + str.slice(1); }; console.log(fist
阅读全文
摘要:结果: /** * * @param {*} len 需要生成的长度 * @returns */ const randomString = (len) => { let chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz123456789'; let
阅读全文
摘要:结果: const people = [ { name: 'Alice', age: 21 }, { name: 'Max', age: 20 }, { name: 'Jane', age: 20 } ]; /** * * @param {*} objectArray 数组 * @param {*}
阅读全文
摘要:原数据 转换后的数据 代码 var arr = [ [ "113.25128", "23.12635275", "186" ], [ "113.263104", "23.11854361", "124" ], [ "113.268259", "23.16776212", "145" ], [ "11
阅读全文
摘要:/** * * @param {*} _arr 数组 * @param {*} _this 要删除的字段 动态 */ var _arr = [ {zjhm:123,id:0,name:'李四'}, {zjhm:123,id:1,name:'李五'}, {zjhm:123,id:2,name:'李六'
阅读全文