當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JQuery isPlainObject()用法及代碼示例

jQuery中的isPlainObject()方法用於檢查對象是否為普通對象。

用法:

jQuery.isPlainObject( obj )

參數:此方法接受上麵提到並在下麵描述的單個參數:



  • obj:此參數保存將被檢查以查看其是否為普通對象的對象。

返回值:它返回布爾值。

以下示例說明了jQuery中isPlainObject()方法的用法:

範例1:在此示例中,isPlainObject()方法檢查對象以查看其是否為普通對象。

<!DOCTYPE html> 
<html> 
  
<head> 
    <meta charset="utf-8"> 
    <title>JQuery | isPlainObject() method</title> 
    <script src= 
"https://code.jquery.com/jquery-3.4.1.js"> 
    </script> 
  
</head> 
  
<body style="text-align:center;"> 
  
    <h1 style="color:green">  
        GeeksforGeeks  
    </h1> 
  
    <h3>JQuery | isPlainObject() method</h3> 
    <b>Whether '{}' is a Plain Object:</b> 
    <p></p> 
  
    <script> 
        $("p").append("" + $.isPlainObject({})); 
    </script> 
</body> 
  
</html>

輸出:

範例2:在此示例中,isPlainObject()方法還檢查對象以查看其是否為普通對象。

<!DOCTYPE html> 
<html> 
  
<head> 
    <meta charset="utf-8"> 
    <title>JQuery | isPlainObject() method</title> 
    <script src= 
"https://code.jquery.com/jquery-3.4.1.js"> 
    </script> 
  
</head> 
  
<body style="text-align:center;"> 
  
    <h1 style="color:green">  
        GeeksforGeeks  
    </h1> 
  
    <h3>JQuery | isPlainObject() method</h3> 
    <p id="geek1"> 
      Whether 'document.location' is a Plain Object:  
    </p> 
    <p id="geek2">Whether String is a Plain Object:  
    </p> 
    <script> 
        
        // Document.location 
        $("#geek1").append("" + $.isPlainObject(document.location)); 
        
        // string = "Shubham_Singh" 
        $("#geek2").append("" + $.isPlainObject("Shubham_Singh")); 
    </script> 
</body> 
  
</html>                                      

輸出:




相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 JQuery | isPlainObject() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。