---- 在传统的WINDOWS EXE程序中,模态对话框经常出现。例如,写字板程序(WORDPAD.EXE)中的“查看/选项(O)...”菜单被点中后,跳出“选项”对话框,用户一定要响应该对话框,如果该对话框不关闭,是无法回到主窗口的。这经常被应用于要求用户输入多个参数的场合。我们在浏览器中也可以简单地实现该功能。 
---- 在IE浏览器中,要求用户输入可以使用VBScript的INPUTBOX函数、或者J Script的window.prompt方法,但是界面都比较单调,并且只能传递一个参数,而用DHTML来实现就灵活多了。 ---- 1. 基本语法 ---- window对象有一个方法称为showModalDialog,我们可以在页面按钮的onclick中写如下代码: < BUTTON onclick="window.showModalDialog
('dialog.htm')" >Search< /BUTTON >---- 系统会在新窗口中打开dialog.htm页面,并且等待用户响应,如果用户不响应该页面,那么主页面将得不到光标。 
---- 在dialog.htm中设置window对象的returnValue属性,就可以让主页面得到返回值。例如,在页面的确定按钮的onclick中写: window.returnValue = window.
    document.all.iptPeopleID.value---- 将输入框iptPeopleID的值赋给window对象的returnValue属性。在主页面中就可以得到这个值: 
    var str = showModalDialog("dialog1.htm")---- 2. 传递初始化值 
---- 如果要向模态页面中传递初始化值,可以在主页面中用如下语句: var cSearchValue=showModalDialog
('dialog.htm', 'ABC')
在dialog.htm中使用window.dialogArguments
属性可以得到'ABC'。例如:
< SCRIPT FOR=window EVENT=onload LANGUAGE="JScript" >
if (window.dialogArguments != null)
        window.document.all.iptPeopleID.value = window.dialogArguments;
< /SCRIPT >---- 3. 传递多个数值 
---- 如果要向模态页面中传递多个参数,可以先在主页面中定义一个对象, function myDialog() {
    var str1;
    var str2;
}---- 显示模态页面之前初始化该对象,然后调用showModalDialog方法。 
function WelcomeYou(iniStr1,iniStr2) {
    myDialog.str1 = iniStr1;
    myDialog.str2 =iniStr2 ;if (showModalDialog("dialog2.htm", myDialog)
==false) //将对象传入
......---- 在模态页面中,可以用这样的代码 
window.document.all.iptID.value= 
window.dialogArguments.str1
来引用数值,或者用这样的代码对之赋值
window.dialogArguments.str1 =
window.document.all.iptID.value---- 完整例程如下: 
---- 对于只传递一个参数的情况,见:Main1.htm和dialog1.htm。 ---- 对于传递多个参数的情况,见:Main2.htm和dialog2.htm。 
父窗体:
dim xxx '返回值
dim yyy '传到子窗体的参数 
var xxx = ShowModalDialog('xxx.asp','yyy','dialogWidth:100px;DialogHeight=290px;status:no')
子窗体:
dim yyy '从父窗体传来的参数
dim xxx '传回父窗体的参数 
yyy = window.dialogArguments
xxx = window.returnValue

解决方案 »

  1.   

    showModalDialog MethodCreates a modal dialog box that displays the specified HTML document.SyntaxvReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
    ParameterssURL: Required. String that specifies the URL of the document to load and display. vArguments: Optional. Variant that specifies the arguments to use when displaying the document. Use this parameter to pass a value of any type, including an array of values. The dialog box can extract the values passed by the caller from the dialogArguments property of the window object. sFeatures: Optional. String that specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values: 
    dialogHeight:iHeight Sets the height of the dialog window (see Res for default unit of measure). 
    dialogLeft:iXPos Sets the left position of the dialog window relative to the upper-left corner of the desktop. 
    dialogTop:iYPos Sets the top position of the dialog window relative to the upper-left corner of the desktop. 
    dialogWidth:iWidth Sets the width of the dialog window (see Res for default unit of measure). 
    center:{ yes | no | 1 | 0 } Specifies whether to center the dialog window within the desktop. The default is yes. 
    help:{ yes | no | 1 | 0 } Specifies whether the dialog window displays the context-sensitive Help icon. The default is yes. 
    resizable:{ yes | no | 1 | 0 } Specifies whether the dialog window has set dimensions. The default for both trusted and untrusted dialog windows is no. 
    status:{ yes | no | 1 | 0 } Specifies whether the dialog window displays a status bar. The default is yes for untrusted dialog windows and no for trusted dialog windows. 
     Return ValueVariant. Returns the value of the returnValue property as set by the window of the document specified in sURL .ResA modal dialog box retains the input focus while open. The user cannot switch windows until the dialog box is closed.Because a modal dialog box can include a URL to a resource in a different domain, do not pass information through the vArguments parameter that the user might consider private.As of Microsoft?Internet Explorer 4.0, you can eliminate scroll bars on dialog boxes. To turn off the scroll bar, set the SCROLL attribute to false in the body element for the dialog window, or call the modal dialog box from a trusted application.Microsoft?Internet Explorer 5 allows further control over modal dialog boxes through the status and resizable values in the sFeatures parameter of the showModalDialog method. Turn off the status bar by calling the dialog box from a trusted application, such as Microsoft?Visual Basic?or an HTML Application (HTA), or from a trusted window, such as a trusted modal dialog box. These applications are considered to be trusted because they use Microsoft?Internet Explorer interfaces instead of the browser. Any dialog box generated from a trusted source has the status bar turned off by default. Resizing is turned off by default, but you can turn it on by specifying resizable=yes in the sFeatures string of the showModalDialog method.You can set the default font settings the same way you set Cascading Style Sheets (CSS) attributes (for example, "font:3;font-size:4"). To define multiple font values, use multiple font attributes.The default unit of measure for dialogHeight and dialogWidth in Internet Explorer 4.0 is the em; in Internet Explorer 5 it is the pixel. For consistent results, specify the dialogHeight and dialogWidth in pixels when designing modal dialog boxes.Although a user can manually adjust the height of a dialog box to a smaller value 梡rovided the dialog box is resizable 梩he minimum dialogHeight you can specify is 100 pixels.To override center, even though the default for center is yes, you can specify either dialogLeft and/or dialogTop.ExampleThis example uses the showModalDialog method to open a customized dialog box.<SCRIPT>
    function fnRandom(iModifier){
       return parseInt(Math.random()*iModifier);
    }
    function fnSetValues(){
       var iHeight=oForm.oHeight.options[
          oForm.oHeight.selectedIndex].text;
       if(iHeight.indexOf("Random")>-1){
          iHeight=fnRandom(document.body.clientHeight);
       }
       var sFeatures="dialogHeight: " + iHeight + "px;";
       return sFeatures;
    }
    function fnOpen(){
       var sFeatures=fnSetValues();
       window.showModalDialog("showModalDialog_target.htm", "", 
          sFeatures)
    }
    </SCRIPT><FORM NAME=oForm>
    Dialog Height <SELECT NAME="oHeight">
       <OPTION>-- Random --
       <OPTION>150
       <OPTION>200
       <OPTION>250
       <OPTION>300
    </SELECT>Create Modal Dialog Box
    <INPUT TYPE="button" VALUE="Push To Create" 
       onclick="fnOpen()">
    </FORM>Applies To
    Platform Version 
    Win16:  
    Win32:  
    WinCE:  
    Unix:  
    Mac:  
    Version data is listed when the mouse hovers over a link, or the link has focus. Move the mouse cursor over an element in the Applies To list to display availability information for the listed platforms. Internet Explorer does not expose this member on platforms that are not listed. 
      

  2.   

    http://go6.163.com/colorweb/js/mengxhdialog.htm