JSLite - 测试操作
如有疑问欢迎到这些地方交流,欢迎加入JSLite.io组织团伙共同开发!
$.isDocument
判断对象是否为【document】。
$.isDocument(document) //=> true
$.isWindow
确定参数是否为一个窗口(window对象),如果是则返回true。这在处理iframe时非常有用,因为每个iframe都有它们自己的window对象,使用常规方法obj==window校验这些objects的时候会失败。
$.isFunction
判断对象是否为函数【function】。
$.isFunction(function(){}) //=> true
$.isObject
判断是否为
Object
。
$.isObject({}) //=> true
$.isPlainObject
$.isPlainObject(object) => boolean
如果通过 "{}" 或者 "new Object" 创建的则返回true。判断对象是否是纯粹的对象。
$.isPlainObject({}) // => true $.isPlainObject(new Object) // => true $.isPlainObject(new Date) // => false $.isPlainObject(window) // => false
$.isArray
判断是否为【数组】。
$.isArray([1,2,3]) //=> true
$.isjson
判断是否为【数组】。
$.isJson({}) //=> true
$.contains
$.contains(parent, node) => boolean
parent
是否包含node
节点对象。
$.contains($("#box")[0],$(".boxss")[0]) //=> parent是否包含node节点对象
$.likeArray
判断对象是否为数组或者是字符。
$.likeArray([1,2,3]) //=> true $.likeArray("222") //=> true
$.type
获取javascript 对象的类型。可能的类型有:
null
undefined
boolean
number
string
function
array
date
regexp
object
error
。
$.type(true) //=> Boolean $.type("div") //=> String
$.matches
如果当前节点能被指定的CSS选择器查找到,则返回
true
,否则返回false
。$.matches(element,selector) => boolean
$.matches($("#box")[0], "#box")//=> true
is
判断当前匹配的元素集合中的元素,是否为一个选择器,DOM元素 is(selector) => boolean
is(element) => boolean
$("#box").is("div"); //=> true $("#box").is("#box"); //=> true $("#box").is("#boxsss"); //=> false $("div").is($("#box")[0]) //=> true 节点是否在 $("#box")[0] 是否再集合中