Members
hasClass
为元素移除class
- Source:
hasClass
为元素替换class
- Source:
hasClass
为元素添加class
- Source:
isFalse
判断是否为真值
Methods
arrayEqual(arr1, arr2) → {Boolean}
判断两个数组(内容/非对象)是否相等
Parameters:
Name | Type | Description |
---|---|---|
arr1 |
Array | 数组1 |
arr2 |
Array | 数组2 |
- Source:
Returns:
- Type
- Boolean
debounce(delay, atBegin, callback) → {function}
函数防抖
与throttle不同的是,debounce保证一个函数在多少毫秒内不再被触发,只会执行一次,
要么在第一次调用return的防抖函数时执行,要么在延迟指定毫秒后调用。
Parameters:
Name | Type | Description |
---|---|---|
delay |
Number | 0或者更大的毫秒数。 对于事件回调,大约100或250毫秒(或更高)的延迟是最有用的。 |
atBegin |
Boolean | 可选,默认为false。 如果`atBegin`为false或未传入,回调函数则在第一次调用return的防抖函数后延迟指定毫秒调用。 如果`atBegin`为true,回调函数则在第一次调用return的防抖函数时直接执行 |
callback |
function | 延迟毫秒后执行的函数。`this`上下文和所有参数都是按原样传递的, 执行去抖动功能时,,调用`callback`。 |
- Source:
Returns:
新的防抖函数。
- Type
- function
Example
适用场景:如在线编辑的自动存储防抖。
deepClone(values) → {Any}
深拷贝,支持常见类型
Parameters:
Name | Type | Description |
---|---|---|
values |
Any |
- Source:
Returns:
- Type
- Any
digitUppercase(n) → {String}
现金额转大写
Parameters:
Name | Type | Description |
---|---|---|
n |
Number |
- Source:
Returns:
- Type
- String
formatPassTime(startTime) → {String}
格式化${startTime}距现在的已过时间
Parameters:
Name | Type | Description |
---|---|---|
startTime |
Date |
- Source:
Returns:
- Type
- String
formatRemainTime(endTime) → {String}
格式化现在距${endTime}的剩余时间
Parameters:
Name | Type | Description |
---|---|---|
endTime |
Date |
- Source:
Returns:
- Type
- String
getByStyle(ele, name) → {String}
获取行间样式属性
Parameters:
Name | Type | Description |
---|---|---|
ele |
HTMLElement | HTMl元素 |
name |
String | css属性名称 |
- Source:
Returns:
css属性值
- Type
- String
getCookie(name) → {String}
根据name读取cookie
Parameters:
Name | Type | Description |
---|---|---|
name |
String |
- Source:
Returns:
- Type
- String
getExplorer() → {String}
获取浏览器类型和版本
- Source:
Returns:
- Type
- String
getKeyName(keycode) → {String}
根据keycode获得键名
Parameters:
Name | Type | Description |
---|---|---|
keycode |
Number |
- Source:
Returns:
- Type
- String
getOS() → {String}
获取操作系统类型
Returns:
- Type
- String
getScrollTop()
获取滚动条距顶部的距离
- Source:
hasClass(ele, cls) → {Boolean}
判断元素是否有某个class
Parameters:
Name | Type | Description |
---|---|---|
ele |
HTMLElement | HTML元素 |
cls |
String | 类名 |
- Source:
Returns:
- Type
- Boolean
html2Str(ele) → {String}
html转成字符串
Parameters:
Name | Type | Description |
---|---|---|
ele |
HTMLElement | HTMl元素 |
- Source:
Returns:
html字符串
- Type
- String
isArray(value) → {Boolean}
判断是否为数组
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
- Source:
Returns:
- Type
- Boolean
isBoolean(value) → {Boolean}
判断是否为布尔类型
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
- Source:
Returns:
- Type
- Boolean
isColor(str) → {Boolean}
判断是否为16进制颜色,rgb 或 rgba
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
- Source:
Returns:
- Type
- Boolean
isDate(value) → {Boolean}
判断是否为日期类型
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
Returns:
- Type
- Boolean
isEmail(str) → {Boolean}
判断是否为邮箱地址
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
- Source:
Returns:
- Type
- Boolean
isEmptyObject(obj) → {Boolean}
判断`obj`是否为空
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object |
- Source:
Returns:
- Type
- Boolean
isFalse(o) → {Boolean}
判断是否为假值
Parameters:
Name | Type | Description |
---|---|---|
o |
* |
- Source:
Returns:
- Type
- Boolean
isFunction(value) → {Boolean}
判断是否为函数
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
- Source:
Returns:
- Type
- Boolean
isIdCard(str) → {Boolean}
判断是否为身份证号
Parameters:
Name | Type | Description |
---|---|---|
str |
String | Number |
- Source:
Returns:
- Type
- Boolean
isLeapYear(year) → {Boolean}
是否为闰年
Parameters:
Name | Type | Description |
---|---|---|
year |
Number |
- Source:
Returns:
- Type
- Boolean
isNull(value) → {Boolean}
判断是否为null
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
Returns:
- Type
- Boolean
isNumber(value) → {Boolean}
判断是否为数字类型
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
- Source:
Returns:
- Type
- Boolean
isObj(value) → {Boolean}
判断是否为对象
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
Returns:
- Type
- Boolean
isPC() → {Boolean}
判断是否为PC端
Returns:
- Type
- Boolean
isPhoneNum(str) → {Boolean}
判断是否为手机号
Parameters:
Name | Type | Description |
---|---|---|
str |
String | Number |
- Source:
Returns:
- Type
- Boolean
isSameDay(date1, date2) → {Boolean}
判断是否为同一天
Parameters:
Name | Type | Description |
---|---|---|
date1 |
Date | |
date2 |
Date | 可选/默认值:当天 |
- Source:
Returns:
- Type
- Boolean
isString(value) → {Boolean}
判断是否为字符串类型
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
- Source:
Returns:
- Type
- Boolean
isSupportWebP() → {Boolean}
判断浏览器是否支持webP格式图片
- Source:
Returns:
- Type
- Boolean
isUndefined(value) → {Boolean}
判断是否为undefined
Parameters:
Name | Type | Description |
---|---|---|
value |
* |
- Source:
Returns:
- Type
- Boolean
isUrl(str) → {Boolean}
判断是否为URL地址
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Returns:
- Type
- Boolean
offset(ele) → {Object}
获取一个元素的距离文档(document)的位置,类似jQ中的offset()
Parameters:
Name | Type | Description |
---|---|---|
ele |
HTMLElement |
Returns:
- Type
- Object
parseQueryString(url) → {Object}
url参数转对象
Parameters:
Name | Type | Description |
---|---|---|
url |
String | default: window.location.href |
- Source:
Returns:
- Type
- Object
randomColor() → {String}
随机生成颜色
- Source:
Returns:
- Type
- String
randomNum(min, max) → {Number}
生成指定范围[min, max]的随机数
Parameters:
Name | Type | Description |
---|---|---|
min |
Number | |
max |
Number |
- Source:
Returns:
- Type
- Number
removeCookie(name)
根据name删除cookie
Parameters:
Name | Type | Description |
---|---|---|
name |
String |
- Source:
scrollTo(to, duration)
在${duration}时间内,滚动条平滑滚动到${to}指定位置
Parameters:
Name | Type | Description |
---|---|---|
to |
Number | |
duration |
Number |
- Source:
setCookie(name, value, days)
设置Cookie
Parameters:
Name | Type | Description |
---|---|---|
name |
String | |
value |
String | |
days |
Number |
- Source:
setScrollTop(value)
设置滚动条距顶部的距离
Parameters:
Name | Type | Description |
---|---|---|
value |
Number |
- Source:
siblings(ele) → {Array}
获取兄弟节点
Parameters:
Name | Type | Description |
---|---|---|
ele |
HTMLElement | HTMl元素 |
- Source:
Returns:
兄弟节点的数组
- Type
- Array
str2Html(str) → {HTMLElement}
字符串转html
Parameters:
Name | Type | Description |
---|---|---|
str |
String | 字符串 |
- Source:
Returns:
兄弟节点的数组
- Type
- HTMLElement
stringfyQueryString(obj) → {String}
对象序列化
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object |
- Source:
Returns:
- Type
- String
timeLeft(startTime, endTime) → {Object}
${startTime - endTime}的剩余时间,startTime大于endTime时,均返回0
Parameters:
Name | Type | Description |
---|---|---|
startTime |
Date | String | |
endTime |
Date | String |
- Source:
Returns:
{ d, h, m, s } 天 时 分 秒
- Type
- Object
viewModel(inputObj, outputObj)
简易双向绑定
Parameters:
Name | Type | Description |
---|---|---|
inputObj |
Object | 输入的input |
outputObj |
Object | 输出的input |
- Source:
windowResize(downCb, upCb)
H5软键盘缩回、弹起回调
当软件键盘弹起会改变当前 window.innerHeight,监听这个值变化
Parameters:
Name | Type | Description |
---|---|---|
downCb |
function | 当软键盘弹起后,缩回的回调 |
upCb |
function | 当软键盘弹起的回调 |
- Source: