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 | 任意類型 需要進行判斷的任意值。 |