Count the number of milliseconds between the two click events on a paragraph using jquery

  • جي كويري

Count the number of milliseconds between the two click events on a paragraph using jquery

الأجوبة

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
 <meta charset="utf-8">
 <title>Count the number of milliseconds between the two click events on a paragraph</title>
 </head>
 <body>
 <p>Count the number of milliseconds between the two click events on a paragraph </p>
   <div>Click on the above paragraph</div>
   </body>
   </html>

JavaScript Code :

var lastt, tdiff;
$( "p" ).click(function( event ) {  if (lastt) {
  tdiff = event.timeStamp - lastt;
  $( "div" ).append( "Time since last event: " + tdiff + "<br>" );
   } 
   else {
     $( "div" ).append( "<br>Click again.<br>" );
	   }
	 lastt = event.timeStamp;
	});
هل كان المحتوى مفيد؟

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...