- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,在我的开发机器上,我有以下代码:
JScript
setInterval(function () { myTimer(); }, 1000);
function myTimer() {
var d = new Date();
var hrs = d.getHours();
var min = d.getMinutes();
var sec = d.getSeconds();
var dayOfWeek = d.getDay();
// Let's do this logically.
// To get the number of victims so far today we need to know how many seconds have passed so far today.
var totalSeconds = sec + (min * 60) + (hrs * 3600); // Number of Seconds passed so far today.
// Now multiply that by 14 in accordance with Symantec's research.
var VictimsToday = totalSeconds * 14;
// To get the number of victims this week we need to multiply
// The number of seconds in a day by the number of full days and add the number of seconds of this partial day.
var TotalSecondsInADay = 86400; // According to Google.
var DaysSoFarThisWeek = dayOfWeek + 1; // Removes today as a partial day.
// We already know how many seconds are in this partial day = totalSeconds
// So our calculation is
var tsD = TotalSecondsInADay * DaysSoFarThisWeek;
var VictimsThisWeek = (totalSeconds + tsD) * 14;
// Now we get the Day of the Year remove today as a partial day and calculate
// Number of seconds a day by the number of complete days so far + todays partial day
var DOY = DayOfYear();
var tsY = DOY * totalSeconds;
var VictimsThisYear = (totalSeconds + tsY) * 14;
document.getElementById("FooterStatistics").innerHTML = Intl.NumberFormat().format(VictimsToday);
document.getElementById("FooterStatistics2").innerHTML = Intl.NumberFormat().format(VictimsThisWeek);
document.getElementById("FooterStatistics4").innerHTML = Intl.NumberFormat().format(VictimsThisYear);
}
function DayOfYear() {
var today = new Date();
var first = new Date(today.getFullYear(), 0, 1);
var theDay = Math.round(((today - first) / 1000 / 60 / 60 / 24) + 0.5, 0);
return theDay;
}
HTML 为:
body
<div id="FooterStatistics"></div>
<div id="FooterStatistics2"></div>
<div id="FooterStatistics4"></div>
现在在开发机器上,DIV 中返回的计算结果是:
但是,当我在 W3Schools Tryit 编辑器上运行此命令时:http://www.w3schools.com/js/tryit.asp?filename=tryjs_date_getday
我得到了完全不同的计算结果:
现在我知道由于时区差异,数字会有所不同 - 实际计算不应有所不同。 Dev 机器的第二个结果比第一个结果小,这是不应该的,而第三个结果显然甚至不是一个数字 - TryIt 编辑器中的结果提供了更合理的答案。
怎么会这样?
最佳答案
创建应用程序时,继续使用 console.log()
检查值。这确实有助于了解 future 正在发生的事情。虽然这不能替代调试,但它会有所帮助。只有当您的代码即将上线,或者您确定它可以工作并且抽象得很好时,您才能删除它们。
PS:避免使用 w3schools.com
。使用MDN 。好多了。
关于javascript - Jscript 在开发和测试机器上返回不同的(计算的)结果 - 使用相同的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23994604/
我编写 JSCript 并使用 WindowsScriptHost 运行它。但是,它似乎缺少 Array.forEach()。 ['a', 'b'].forEach(function(e) {
在我的环境中,如果我使用 JScript 语法创建一个类: class test{ } 然后将其保存到名为“test.js”的文件并使用 wscript 运行它,我在第 1 行收到 Microsoft
我有一个“for”循环,它必须转换数千个相互不依赖的文件中的内容。代码是用 JScript 编写的。我想添加一些线程代码来在 CPU 之间分发文件,因为其他的似乎是空闲的。我试图在 JScript 中
大家早上好 我目前正在编写一个小的 batch/jscript/hta 程序。 在下面的程序中,我读取了一个文本输入字段,将文本传递给批处理并在那里显示: HTA Buttons windo
我无法在我的机器上的 IE8 中打开 gwt-html 页面(在 Mozila FF 中加载)。当我在我的 html 页面中调试 Js 时,我收到以下错误消息Jscript 调试器。中断 JScrip
var scriptFile = $(tempNode).attr("customJScriptSrc"); 当通过这个我得到 “Reference Error: Can’t find variabl
有没有办法使用 Windows Scripting Host 在注册表中搜索特定键? 我正在使用 JavaScript (Jscript/VBScript?) 来执行此操作,而 msdn 库未提及任何
请考虑以下WSH代码段: var query = GetObject(“winmgmts:”)。ExecQuery(“SELECT Name FROM Win32_Printer”,“WQL”,0);
我有一个用 JScript(不是 javascript)编写的函数,我需要暂停直到某个全局变量变为真。当在 ajax 响应后调用另一个函数时,全局变量更改为 true: function(req, e
var FSO = new ActiveXObject("Scripting.FileSystemObject"); var BFolder = "C:\\temp"; var XFolder
重新发布工作代码 (我试图从我的 ActiveX 组件获取数组,但没有成功。当我运行脚本时,我得到空消息框,但我知道数组在那里:) var objMain, objAdapt, lgCount, st
几年来,我一直在 EA 中广泛使用脚本。今天早上,我进入 EA 开始构建新脚本,但脚本似乎不再有效。我试着写“Hello World”,甚至写了一个有语法错误的脚本。它既不检测错误也不运行脚本。 我看
我正在尝试在我的网页中构建一个“ Accordion ”样式的可折叠 div,如 w3c 学校此处所述... accordion description 我已经完成了大部分工作 - 我的代码是这样的:
我最近注意到,我用来编译和使用 C# 文件(如我的应用程序中的脚本)的库 (CSScript) 也可以编译 VB 和 JScript。不过,我的一个应用程序使用了 await/async (C# 5)
我一直在尝试查找一些关于 jscript 编程的文档,这样我就可以自己编写它,但是找不到所需的文档.... 我的问题是:我一直在尝试编写一个 jscript,它将通过网络连接并添加打印机...。其中一
这看起来应该很容易。我以前从未使用过 JScript,我正在查看 microsoft 提供的 JScript api,但没有运气。这是我所拥有的: var fso, tf; fso = new
我可以在“Microsoft JScript”中使用什么来代替带有字符串的length()。 String类没有方法length()或者我没有找到。获取字符串长度的最佳方法是什么? 最佳答案 应该有一
在config.txt中,我有以下字符串: Dispatcher=argo Address=10.5.23.14 User=joe 在我的script.js中,我有变量: var Dispatcher
我正在尝试建立一个小型 JavaScript 实验室。在实验室中,首先我创建了一个 Animal 对象: function Animal(species, nature) { this.speci
我收到运行时错误 Microsoft JScript 运行时错误:“document.getElementById(...)”为 null 或不是对象 我正在使用母版页。 谁能帮帮我 最佳答案 发
我是一名优秀的程序员,十分优秀!