JQuery now()方法

JQuery now()方法

jQuery中的这个now()方法是用来返回一个代表当前时间的数字。

语法:

jQuery.now()

参数: now()方法不接受任何参数。

返回值:它返回代表当前时间的数字。

例子1:在这个例子中,now()方法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>                                                                                            

输出:
点击前:
JQuery now()方法
点击后:
JQuery now()方法

例子2:在这个例子中,now()方法alert函数显示了毫秒数。

<!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 now()方法
点击后:
JQuery now()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程