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.messagecatch 句で使用して、スローされたエラーを表示しようとすることができます。サイドバー ガジェットの作成に関するこのリンクを確認してください。

于 2010-05-03T07:41:36.777 に答える
1

「System.Time」参照で何をしようとしているのかわかりません。JavaScript の「日付」関数を使用してみてください。ここに良いリファレンスがあります http://www.w3schools.com/jsref/jsref_obj_date.asp

また、これがあなたが投稿した内容の単なるタイプミスであるかどうかはわかりませんが、終了の「}」が欠落しているようです

 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 に答える