1

对于我的第一个 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>
4

2 回答 2

1

您的format日期方法不是本机 Date 方法。你有没有在任何地方定义它?您可以尝试curTime.innerHTML = e.message在 catch 子句中使用显示抛出的错误。检查此链接以创建侧边栏小工具。

于 2010-05-03T07:41:36.777 回答
1

我不确定您要如何处理“System.Time”引用。尝试使用 JavaScript 的“日期”函数。这是一个很好的参考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 '}'

 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) {}
 } // <--- Here
于 2010-05-03T13:17:58.987 回答