jQuery中的now()方法用於返回代表當前時間的數字。
用法:
jQuery.now()
參數:now()方法不接受任何參數。
返回值:它返回代表當前時間的數字。
範例1:在此示例中,now()方法a使用innerHTML函數顯示毫秒數。
<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>JQuery | now() 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 | now() method</h3> 
    <button onclick="geek()">Try it</button> 
  
    <p id="demo"></p> 
      
    <script> 
    function geek() { 
      var n = jQuery.now(); 
      document.getElementById("demo").innerHTML = n/3600; 
    } 
    </script> 
</body> 
</html>                                                                                            輸出:
點擊前:

點擊後:

範例2:在此示例中,now()方法a顯示具有警報函數的毫秒數。
<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>JQuery | now() 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 | now() method</h3> 
    <button onclick="geek()">Try it</button> 
      
    <script> 
    function geek() { 
      var n = jQuery.now(); 
      alert("Number of milliseconds:" + n); 
    } 
    </script> 
</body> 
</html>                                        輸出:
點擊前:

點擊後:

相關用法
- JQuery off()用法及代碼示例
 - JQuery die()用法及代碼示例
 - JQuery is()用法及代碼示例
 - JQuery css()用法及代碼示例
 - JQuery before()用法及代碼示例
 - JQuery add()用法及代碼示例
 - JQuery get()用法及代碼示例
 - JQuery attr()用法及代碼示例
 - JQuery ajax()用法及代碼示例
 - JQuery ajaxSetup()用法及代碼示例
 - JQuery param()用法及代碼示例
 - JQuery unload()用法及代碼示例
 - JQuery toggle()用法及代碼示例
 
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 JQuery | now() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
