简体   繁体   English

这个JavaScript / jQuery代码怎么了?

[英]What's wrong with this JavaScript/jQuery code?

Why won't my code show " 0 a.004? It shows "a.004 0 " instead. 为什么我的代码不显示“ 0 a.004”?而是显示“ a.004 0 ”。

 $(document).ready(function() { /* I will eventually replace my example with this var d = new Date(); var h = d.getUTCHours(); var m = d.getUTCMinutes(); var s = d.getUTCSeconds(); var d = new Date(); */ var h = 0; var m = 144; var s = 2; var u = (s / 864) + (m / 14.4) + (h / 0.24); // Tried as an example: var u = 11.060 u = u.toString(12); if (u + 1 < 12) { u = "0" + u; } var n = u.substring(0, 6); $("#time").append(n); }); 
 #time { color: #000; font-family: "Courier New"; font-size: 60pt; text-align: center; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="time"></div> 

By the way, I got the metric time idea from this website , and decided to put it in base-12. 顺便说一句,我从该网站获得了公制时间的想法,并决定将其设置为12基。

Looks like you need to compare against the 12 before your toString converting to base 12. Updated snippet in the below code: 看起来您需要将toString转换为12之前与12进行比较。以下代码中的更新代码段:

 $(document).ready(function() { /* I will eventually replace my example with this var d = new Date(); var h = d.getUTCHours(); var m = d.getUTCMinutes(); var s = d.getUTCSeconds(); var d = new Date(); */ var h = 0; var m = 144; var s = 2; var u = (s / 864) + (m / 14.4) + (h / 0.24); var n = (u + 1 < 12 ? '0' : '') + u.toString(12).substring(0, 6); $("#time").append(n); }); 
 #time { color: #000; font-family: "Courier New"; font-size: 60pt; text-align: center; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="time"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM