补充工具栏小工具的事件不起作用

时间:2014-08-20 20:55:56

标签: javascript html

我是html和JavaScript的新手,我已经阅读了如何在msdn中制作小工具,一件好事就是开始掌握这些语言......

在我的js / settings.js中,我写道:

System.Gadget.settingsUI =“settings.html”;

System.Gadget.onSettingsClosing = SettingsClosing;

function SettingsClosing(event)
{
    // Save the settings if the user clicked OK.
    if (event.closeAction == event.Action.commit)
    {
        var e =document.getElementById("HDA");
        System.Gadget.Settings.write("SelectedNumber",e.options[sel.selectedIndex].text);
    }
    // Allow the Settings dialog to close.
    event.cancel = false;
}

System.Gadget.onSettingsClosed = SettingsClosed;

function SettingsClosed(event)
{
    // User hits OK on the settings page.
    if (event.closeAction == event.Action.commit)
    {
        userEntry =System.Gadget.Settings.readString("SelectedNumber");
        document.getElementById("text1").value=userEntry;
    }
}

这是html文档:

<html><html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <script language="JavaScript" src="js/settings.js"></script>
        <title>Hijri Date</title>
   <style type="text/css">
       #HDA
      {
        width: 90px;
        font-family: verdana;

      }
  body
        {
            margin: 0;
            width: 130px;
            height:150px;
            font-family: verdana;
            font-weight: bold;
            color:green;
            border-radius:5px;
            font-size: 13px;
        }
        </style>
    </head>

    <body>
        <p id="text1"> Hijri Date Adjustment : </p>
        <select name="Hijri Date Adjustment" id="HDA">
          <option value="3">3</option>
          <option value="2">2</option>
          <option value="1">1</option>
          <option value="0">0</option>
          <option value="-1">-1</option>
          <option value="-2">-2</option>
          <option value="-3">-3</option>
</select>
    </body>
</html>

当我按下OK按钮时,设置窗口不会关闭,并且段落文本不会改变。

1 个答案:

答案 0 :(得分:0)

sel.selectedIndex

未定义。你可以试试

e.selectedIndex

只要JavaScript抛出错误,设置对话框就不会再关闭。这有时会让你发疯;)