Home  >  Article  >  Web Front-end  >  Integration of daily commonly used functions in JS

Integration of daily commonly used functions in JS

php中世界最好的语言
php中世界最好的语言Original
2018-03-12 15:37:531658browse

This time I will bring you the daily commonly used functions of JSIntegration, what are the precautions for using JS daily commonly used functions to integrate, the following is a practical case, let's take a look.

Directly download lutils.min.js or lutils.full.min.js in the min directory
It is recommended to package it yourself according to your actual needs
You can use Object.keys (lutils) View the built-in encapsulation function

BrowserUsage examples:

   
Cookie
getCookie 根据name读取Cookie
removeCookie 根据name删除Cookie
setCookie 添加Cookie
Json (包含Object与Array)
array2Tree 数组转为树状格式数组
deepClone 深拷贝,支持常见类型
isEmpty 判断对象或数组是否为空
copy 一般拷贝,浅拷贝
arrayEqual 判断数组是否相等
countArray 判断数组项在数组中出现的次数
reverse Object数据翻转 key value翻转 或 数组翻转
optionArr2Obj 例如:[{value: '选项1',label: '黄金糕'},...] 转 {'黄金糕':'选项1',...}
obj2OptionArr 例如:{'黄金糕':'选项1',...} 转[{value: '选项1',label: '黄金糕'},...]
initRangeArray 生成指定范围的整数数组
Str (String)
replaceAll 替换所有
digitUppercase 现金额转大写
rtrim 去除字符串前后空格
ltrim 去除左空格
trim 去除右空格
reverse 字符串倒转
ucfirst 英文字符串首字母大写
Support
webP 判断浏览器是否支持webP格式图片
webP2 判断浏览器是否支持webP格式图片
Keycode
getName 根据keycode获得键名
File
toBlobURL 文件转BlobURL
toDataURL 文件转DataURL
base64UrlToBlob base64转Blob 或 ArrayBuffer
downloadByUrl 通过url下载文件
Num (Number)
accAdd 精确的加法计算
accSub 精确的减法计算
accMul 精确的乘法计算
accDiv 精确的除法计算
Date (日期时间处理推荐结合moment.js使用)
string2date 字符串时间转为Js Date类型
formatPassTime  格式化${startTime}距现在的已过时间
formatRemainTime 格式化现在距${endTime}的剩余时间
isSameDay 判断是否为同一天
getTimeStamp 时间戳
Validate
messages 默认验证提示
required 非空验证
email 邮箱验证
url url验证
date 时间验证
dateISO 时间验证,例如:2009-06-23,1998/01/22 只验证格式
number 数字验证
digits 数字验证
isarr 是否是数组
minlength 最小长度验证
maxlength 最大长度验证
rangelength 长度范围验证
min 最小值验证
max 最大值验证
range 值范围验证
equalTo 类型与值是否相等
mphone 手机号验证
tphone 动画号验证
idCard 身份证验证
postal 邮编验证
Url
getQueryObject 将url参数获取为对象
stringfyQueryString 对象序列化为url参数
getQueryString 根据name获取url参数值
Fun (Function)
throttle 函数节流
debounce 函数防抖
Random
randomColor 随机生成颜色
randomNum 生成指定范围随机数
randomChars 生成随机字符串([AZ],[az],[0~9])
randomChars 生成随机字符串([AZ],[az],[0~9])
randomSort 打乱数组内部顺序
UUID 生成UUID
Dom
addClass 为元素添加class
getScrollTop 获取滚动条距顶部的距离
hasClass 判断元素是否有某个class
offset 获取一个元素的距离文档(document)的位置,类似jQ中的offset()
removeClass 为元素移除class
scrollTo 在${duration}时间内,滚动条平滑滚动到${to}指定位置
setScrollTop 设置滚动条距顶部的距离
windowResize H5软键盘缩回、弹起回调
append 追加html类似jQ中的html()
fullscreen 进入全屏模式
exitFullScreen 退出全屏模式
Xml
json2xml json转xml文本
xml2json xml(Element)转json
parseXml 字符串转xml(Element)
Device
getExplore 获取浏览器类型和版本号
getOS 获取操作系统类型
isWeixin 获取是微信浏览器
Mime
描述消息内容类型
Clipboard
剪切板

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!

Related reading:

How to use canvas to make a useful graffiti drawing board

How to use s-xlsx merge Cell

The above is the detailed content of Integration of daily commonly used functions in JS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn