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


JQuery noop()用法及代碼示例

當用戶希望傳遞不會執行任何操作的函數時,jQuery中的noop()方法為空函數。

用法:

jQuery.noop()

參數:noop()方法不接受任何參數。



返回值:它返回未定義的。

範例1:在此示例中,noop()方法與innerHTML函數一起使用。

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>JQuery | noop() 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 | noop() method</h3> 
    <button onclick="geek()">Try it</button> 
    <br><br> 
    <b> Value Return:</b> 
    <br> 
    <p id="demo"></p> 
   
    <script> 
    function geek() { 
      var n = jQuery.noop(); 
      document.getElementById("demo").innerHTML = n; 
    } 
    </script> 
</body> 
</html>                                                                                            

輸出:
點擊前:

點擊後:

範例2:在此示例中,noop()方法與警報函數一起使用。

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>JQuery | noop() 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 | noop() method</h3> 
    <button onclick="geek()">Try it</button> 
      
    <script> 
    function geek() { 
      var n = jQuery.noop(); 
      alert("Value Return:" + n); 
    } 
    </script> 
</body> 
</html>                                        

輸出:
點擊前:

點擊後:




相關用法


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