jq 常用工具方法
方法 | 作用 | 參數 | 返回值 |
$.type() | 區分所有類型 | 要判斷的變量 | 字符串 |
$.isFunction() | 判斷是否是函數 | 要判斷的變量 | true:是函數
false:不是函數 |
$.isEmptyObject() | 判斷數組和對象是否爲空 | 要判斷的數組和對象名 | true:爲空false:不爲空 |
$.each() | 遍歷數組 | 要遍歷的數組名,function | 無 |
$.merge() | 合併兩個數組,第一個數組會被改變,第二個數組不會 | 數組1,數組2 | 無 |
$.grep() | 數組過濾 | 要過濾的數組,function,boolean | 無 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./jquery-3.4.1.js"></script>
</head>
<body>
<script>
let str=[];
let fff=function(){}
console.log($.type(str))
console.log($.type(fff))
let foo=function(){}
console.log($.isFunction(foo))
console.log($.isEmptyObject(foo))
console.log($.isEmptyObject(['1','2','3']))
let arr=[1,2,3,4,5,6,7,8,9];
$.each(arr,function(i,elem){
console.log(elem)
})
let a=[1,2,3];
let b=[4,5,6];
console.log($.merge(a,b))
console.log(a)
let c=[1,2,3,4,5,6,7,8,9];
let d=$.grep(c,function(v,i){
return v>5
},true)
console.log(d)
</script>
</body>
</html>