Javascript implements countdown (accurate to seconds)_javascript skills
The code is quite simple and practical, so there won’t be much nonsense here. Friends can understand it simply by looking at it
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div id="demo01" class="colockbox">剩余 <i class="day">0</i>天 <i class="hour">0</i>时 <i class="minute">0</i>分 <i class="second">0</i>秒 <input id="end_time_gou" type="hidden" value="2015/08/20 13:00:00"> <input id="now_gou" type="hidden" value="2015/06/25 11:44:08"> </div> <div id="timer" class="colockbox"> </div> <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js"></script> <script> var time_end = $('#end_time_gou').val(); var time_now_server = $('#now_gou').val(); countDown(time_end,time_now_server,"#demo01 .day","#demo01 .hour","#demo01 .minute","#demo01 .second"); function countDown(endtime,now,day_elem,hour_elem,minute_elem,second_elem){ var end_time = new Date(endtime).getTime(),//月份是实际月份-1 current_time = new Date(now).getTime(), sys_second = (end_time-current_time)/1000; var timer = setInterval(function(){ if (sys_second > 0) { sys_second -= 1; var day = Math.floor((sys_second / 3600) / 24); var hour = Math.floor((sys_second / 3600) % 24); var minute = Math.floor((sys_second / 60) % 60); var second = Math.floor(sys_second % 60); day_elem && $(day_elem).text(day);//计算天 $(hour_elem).text(hour<10?"0"+hour:hour);//计算小时 $(minute_elem).text(minute<10?"0"+minute:minute);//计算分 $(second_elem).text(second<10?"0"+second:second);// 计算秒 } else { clearInterval(timer); } }, 1000); } </script> <script type="text/javascript"> var time_now_server,time_now_client,time_end,time_server_client,timerID; time_end=new Date($('#end_time_gou').val());//结束的时间 time_end=time_end.getTime(); time_now_server=new Date($('#now_gou').val());//开始的时间,服务器 time_now_server= time_now_server.getTime(); time_now_client=new Date(); time_now_client=time_now_client.getTime();//本地的时间 time_server_client=time_now_server-time_now_client; setTimeout("show_time("+time_end+","+time_server_client+","+timerID+")",1000); function show_time(time_end,time_server_client,timerID){ var timer = document.getElementById('timer'); if(!timer){return;} timer.innerHTML = timer.innerHTML; var time_now,time_distance,str_time; var int_day,int_hour,int_minute,int_second; var time_now=new Date(); time_now=time_now.getTime()+time_server_client; time_distance=time_end-time_now; if(time_distance>0){ int_day=Math.floor(time_distance/86400000) time_distance-=int_day*86400000; int_hour=Math.floor(time_distance/3600000) time_distance-=int_hour*3600000; int_minute=Math.floor(time_distance/60000) time_distance-=int_minute*60000; int_second=Math.floor(time_distance/1000) if(int_hour<10) int_hour="0"+int_hour; if(int_minute<10) int_minute="0"+int_minute; if(int_second<10) int_second="0"+int_second; str_time=int_day+"天"+int_hour+"小时"+int_minute+"分钟"+int_second+"秒"; timer.innerHTML=str_time; setTimeout("show_time("+time_end+","+time_server_client+","+timerID+")",1000); }else{ timer.innerHTML =timer.innerHTML; clearTimeout(timerID) } } </script> </body> </html>
The above is the entire content of this article, I hope you all like it.

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor
