第一个 Windows 7 小工具运行 javascript 时出现问题
对于我的第一个 Windows 小工具,我正在尝试制作一个显示当前时间和日期的小工具。下面的代码是我的代码,但我不明白为什么 javascript 没有运行。有什么想法吗?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
<title>Clock</title>
<style type="text/css">
body { width: 130px; height: 60px; margin: 1 1 1 2; }
body { font-family: Segoe UI, Arial; font-size: 11px; font-weight: bold; white-space: nowrap; }
</style>
<script type="text/javascript">
var background;
var interval;
var connection_id;
var timeZone;
var now;
function load() {
try {
interval = 1000;
connection_id = 0;
timeZone = System.Time.currentTimeZone;
update();
}
catch(e){}
}
function update() {
try {
now = new Date(Date.parse(System.Time.getLocalTime(timeZone)));
curDate.innerHTML = now.format('M jS, Y');
curTime.innerHTML = now.format('h:i:s A');
clearTimeout(connection_id);
connection_id = setTimeout("update()", interval);
}
catch(e) {}
</script>
</head>
<body onload="load()">
<div id="curDate">
</div>
<div id="curTime">
</div>
</body>
</html>
For my first windows gadget I'm trying to make one that displays the current time and date. The code below is what I have, but I can't figure out why the javascript is not running. Any ideas?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
<title>Clock</title>
<style type="text/css">
body { width: 130px; height: 60px; margin: 1 1 1 2; }
body { font-family: Segoe UI, Arial; font-size: 11px; font-weight: bold; white-space: nowrap; }
</style>
<script type="text/javascript">
var background;
var interval;
var connection_id;
var timeZone;
var now;
function load() {
try {
interval = 1000;
connection_id = 0;
timeZone = System.Time.currentTimeZone;
update();
}
catch(e){}
}
function update() {
try {
now = new Date(Date.parse(System.Time.getLocalTime(timeZone)));
curDate.innerHTML = now.format('M jS, Y');
curTime.innerHTML = now.format('h:i:s A');
clearTimeout(connection_id);
connection_id = setTimeout("update()", interval);
}
catch(e) {}
</script>
</head>
<body onload="load()">
<div id="curDate">
</div>
<div id="curTime">
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您想对“System.Time”引用做什么。尝试使用 JavaScript 的“日期”函数。这是一个很好的参考http://www.w3schools.com/jsref/jsref_obj_date.asp
另外,我不确定这是否只是您发布的内容中的拼写错误,但看起来您缺少结束语“}”
I'm not sure what your trying to do with the 'System.Time' references. Try using the JavaScript 'Date' functions. Here is a good reference http://www.w3schools.com/jsref/jsref_obj_date.asp
Also I am not sure if this is just a typo in what you posted but it looks like your missing a closing '}'
日期的
format
方法不是本机 Date 方法。您在任何地方定义过它吗?您可以尝试在 catch 子句中使用curTime.innerHTML = e.message
来显示引发的错误。检查此链接关于创建侧边栏小工具。The
format
method for your date is not a native Date method. Did you define it anywhere? You could try to display the error that is thrown, usingcurTime.innerHTML = e.message
in your catch clause. Check this link on creating sidebar gadgets.