Javascript 模态对话框不与主HTA窗口通信

Javascript 模态对话框不与主HTA窗口通信,javascript,modal-dialog,hta,Javascript,Modal Dialog,Hta,我在HTA中有一个javascript,如下所示: var result = null; window.showModalDialog("dialog.hta", window, "dialogHeight:300px; dialogWidth:300px"); alert(result); dialog.hta: <html> <head> <title>Dialog box</title> <meta http-eq

我在HTA中有一个javascript,如下所示:

var result = null;
window.showModalDialog("dialog.hta", window, "dialogHeight:300px; dialogWidth:300px");
alert(result);
dialog.hta:

<html>
<head>
     <title>Dialog box</title>
     <meta http-equiv="MSThemeCompatible" content="yes"/>
</head>
<body style="background:#F0F0F0">
     <select id="colors">
          <option selected>Red</option>
          <option>Blue</option>
          <option>Green</option>
          <option>Yellow</option>
     </select><br/>
     <script type="text/javascript">
          function ok(){
               window.dialogArguments.result = colors.getElementsByTagName("option")[colors.selectedIndex].innerHTML;
               window.close();
          }
     </script>
     <button onclick="ok()">OK</button>
     <button onclick="window.close()">Cancel</button>
</body>
</html>

对话框
红色
蓝色
绿色
黄色的

函数ok(){ window.dialogArguments.result=colors.getElementsByTagName(“选项”)[colors.selectedIndex].innerHTML; window.close(); } 好啊 取消
问题是,当我按下OK时,HTA主窗口中的
警报(结果)
总是显示null,即使我在模式对话框中单击OK按钮也是如此。
如何才能在按下“确定”按钮时显示用户在列表中选择的选项,在按下“取消”按钮时显示为空?

这就是模态对话框的工作方式:

在主应用程序中:

// Call a dialog, and store the returned value to a variable
var result = showModalDialog(path, argument, options);
关闭对话框时:

// Set the returnValue
var elem = document.getElementById("colors");
window.returnValue = elem[elem.selectedIndex].text;
top.close();
在对话框中设置
returnValue
后,您可以在对话框关闭后从
result
中读取该值

option
元素在旧IEs中没有
innerHTML
,因此必须使用
text
属性。您还可以向
select
元素添加
value
属性,然后以简单的方式创建返回值:

window.returnValue = document.getElementById('colors').value;