jQuery.isPlainObject() 方法
實例
判斷一個對像是否是純粹的對象。
$ ( function ( ) {
function fun ( html ) {
document . body . innerHTML += " <br> " + html ; }
fun ( $. isPlainObject ( { } ) ) ; // true
fun ( $. isPlainObject ( " test " ) ) ; // false
fun ( $. isPlainObject ( document . location ) ) ; // false ,在IE 8中返回true
} )
嘗試一下»
定義和用法
$.isPlainObject() 函數用於判斷指定參數是否是一個純粹的對象。
注意:宿主對象(或其它被瀏覽器宿主環境使用的對象,用來完成ECMAScript的執行環境)難以進行跨平台的特性檢測。 因此,對於這些對象的實例,$.isPlainObject()在不同的瀏覽器上可能得出不同的結果。
語法
$.isPlainObject( object )
参数 | 描述 |
---|---|
object | 任意类型 需要进行判断的任意值。 |