JAVASCRIPT常用函数集合
2017-03-28 14:21
507 查看
1、删除数组某项
2、当前时间
3、格式化日期
4、判断是否JSON格式对象
5、canvas的相对window窗口坐标转换成canvas内部相对坐标
// Array Remove - By John Resig (MIT Licensed) Array.prototype.remove = function (from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); };
2、当前时间
function getNow() { var date = new Date(); return date.getFullYear() + "-" + (parseInt(date.getMonth()) + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); }
3、格式化日期
function formater(date) { return date.getFullYear() + "-" + (parseInt(date.getMonth()) + 1) + "-" + date.getDate(); }
4、判断是否JSON格式对象
function isJson(obj) { return typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length; }
5、canvas的相对window窗口坐标转换成canvas内部相对坐标
function windowToCanvas(canvas, x, y) { var bbox = canvas.getBoundingClientRect(); return { x: x - bbox.left * (canvas.width / bbox.width), y: y - bbox.top * (canvas.height / bbox.height) }; }
相关文章推荐
- Javascript常用函数及基本教程集合的用法参考
- 常用的Javascript检测函数[zz]
- javascript 常用函数
- 转载 常用的JavaScript脚本集合
- javascript 常用验证函数
- javascript列表框操作函数集合
- JavaScript常用函数
- javascript 常用验证函数
- JavaScript常用功能函数
- javascript 常用验证函数
- Javascript中的数学函数集合
- javascript常用函数!
- JavaScript常用函数
- JavaScript常用函数
- JavaScript 常用函数
- Javascript常用集合(1)
- 最常用的10个javascript自定义函数 选项
- javascript 常用验证函数
- 常用的javascript验证函数
- Javascript中的数学函数集合