完全可以
打开的函数:
function OpenQry(){
var vpara=new Object();
var strurl="query.jsp";
var Feather='status:no;dialogWidth:750px;dialogHeight:480px;center:yes';
vpara=window.showModalDialog(strurl,null,Feather);
//divWait.style.display='none';
if(vpara["btnOK"]){   //如果btnOK为真(按了确定),做什么,本例为关闭父窗
window.close();
}
}
在打开的窗口中加入:
<script language=javascript>
var m_ret=new Object();
m_ret["btnOK"]=true; //默认btnOK为true
function sbClick(flag){//两个按钮的调用事件,flag为标志参数(0或1)
if(flag){m_ret["btnOK"]=true;}else{m_ret["btnOK"]=false;}
Form_QueryUnload();
window.close();
}
function Form_QueryUnload()
{
window.returnValue=m_ret;
}
</script>
在用户没按任何按钮时,要做如下工作
<body onbeforeunload="return Form_QueryUnload()">
确保返回值不会为空,以免js出错

解决方案 »

  1.   

    不要javascript,我想要纯java的代码
      

  2.   

    JOptionPane的四个方法:
    showConfirmDialog Asks a confirming question, like yes/no/cancel. 
    showInputDialog Prompt for some input. 
    showMessageDialog Tell the user about something that has happened. 
    showOptionDialog The Grand Unification of the above three. When one of the showXxxDialog methods returns an integer, the possible values are: YES_OPTION 
    NO_OPTION 
    CANCEL_OPTION 
    OK_OPTION 
    CLOSED_OPTION 
    这几个常数就是返回值。一个小例子:
    //JP.java
    import javax.swing.JOptionPane;
    public class JP
    {
    public static void main(String[] args)
    {
    int v=JOptionPane.showConfirmDialog(null,"You sure you want to enter?","Land",JOptionPane.YES_NO_OPTION);
    if(v==JOptionPane.YES_OPTION) 
    System.out.println("entered");
    else if(v==JOptionPane.NO_OPTION)
    System.out.println("leave");
    System.exit(0);
    }
    }
      

  3.   

    返回值就是JOptionPane中的几个int型数值,有YES_OPTION;NO_OPTION,如果你用ok和cancel那么返回值就是OK_OPTION和CANCEL_OPTION
      

  4.   

    FutureStonesoft(丑石) :同意
      

  5.   

    import java.awt.event.*;
    import java.awt.*;
    class MyDialog extends Dialog implements ActionListener  //建立对话框类。
    {  static final int YES=1,NO=0;
       int message=-1; Button yes,no;
       MyDialog(Frame f,String s,boolean b) //构造方法。
       {  super(f,s,b);
          yes=new Button("Yes"); yes.addActionListener(this);
          no=new Button("No");   no.addActionListener(this);
          setLayout(new FlowLayout());
          add(yes); add(no);
          setBounds(60,60,100,100);
          addWindowListener(new WindowAdapter()
                          {   public void windowClosing(WindowEvent e)
                               { message=-1;setVisible(false);
                               }
                          }
                       );
       }
       public void actionPerformed(ActionEvent e)
       {  if(e.getSource()==yes) 
          { message=YES;setVisible(false);
          }
         else if(e.getSource()==no)
          { message=NO;setVisible(false);
          }
       }
       public int getMessage()
       {  return message;
       }
    }
    class Dwindow extends Frame implements ActionListener 
    {  TextArea text; Button button; MyDialog dialog;
       Dwindow(String s)
       {  super(s);
          text=new TextArea(5,22); button=new Button("打开对话框"); 
          button.addActionListener(this);
          setLayout(new FlowLayout());
          add(button); add(text); 
          dialog=new MyDialog(this,"我有模式",true);
          setBounds(60,60,300,300); setVisible(true);
          validate();
          addWindowListener(new WindowAdapter()
                          {   public void windowClosing(WindowEvent e)
                               { System.exit(0);
                               }
                          }
                       );
       }
       public void actionPerformed(ActionEvent e)
       {  if(e.getSource()==button)
            {  dialog.setVisible(true); //对话框激活状态时,堵塞下面的语句。
              //对话框消失后下面的语句继续执行:
               if(dialog.getMessage()==MyDialog.YES)   //如果单击了对话框的"yes"按钮。
                 {  text.append("\n你单击了对话框的yes按钮");
                 }
               else if(dialog.getMessage()==MyDialog.NO)   //如果单击了对话框的"no"按钮。
                {  text.append("\n你单击了对话框的No按钮");
                }
            }
       }
    }
    public class xe
    {  public static void main(String args[])
       {  new Dwindow("带对话框的窗口");
       }
    }