用模态窗口 模拟 alert 和 confirm 对话框

窗口程序:b.htm

 

< HTML >
    
< HEAD >
        
< TITLE > 塞北的雪 模态 对话框 </ TITLE >
        
< script  language ="javascript" >
            
function doReturn(p) {
                
var p1 = p;
                
var p2 = "";
                
var Args = new Array(p1,p2);
                window.returnValue 
= Args;
                window.close();
            }

            
function doInit() {
                
var p1 = "";
                
var p2 = "m";
                
var Args = new Array(p1,p2);
                Args 
=  window.dialogArguments;
                window.msg.innerText 
= Args[1].toString();
                
if(Args[0]=="1") window.no.style.display='none';
            }

        
</ script >
    
</ HEAD >
    
< BODY  onload ="doInit();" >
        
< br >< br >
        
< div  align ="center" >
            
< div  align ="center"  id ="msg" ></ div >
            
< br >< br >
            
< input  align ="center"  type ="button"  onclick ="doReturn('1')"    value ="是"  ID ="yes"   > &nbsp;&nbsp;
            
< input  type ="button"  onclick ="doReturn('0')"   value ="否"  id ="no"  style ="display:'';"   >
        
</ div >
    
</ BODY >
</ HTML >

 调用页面:a.htm

 

< HTML >
    
< HEAD >
        
< title > 塞北的雪 模态 对话框例子 </ title >
        
< script  language ="javascript" >
            
function openAlert(p1,p2) 
            
{
                
var Args = new Array(p1,p2);
                
var winStyle = "center:yes;resizable:no;dialogHeight:300px"
                
var Args = window.showModalDialog("b.htm", Args,winStyle);
            }

            
            
function openConfirm(p1,p2) 
            
{
                
var Args = new Array(p1,p2);
                
var winStyle = "center:yes;resizable:no;dialogHeight:300px"
                
var Args = window.showModalDialog("b.htm", Args,winStyle);
                
if (Args != null)
                
{
                    
if(Args[0].toString()=="1")
                    
{
                        alert(
"你选择了是");
                        
return;
                    }

                }

                alert(
"你选择了否");
            }

        
</ script >
    
</ HEAD >
    
< body >
        
< input  type ="button"  onclick ="openAlert('1','你居然不认识塞北的雪,你被开除了')"   value ="Alert!"  ID ="Button1" >
        
< input  type ="button"  onclick ="openConfirm('2','你认识塞北的雪吗?')"   value ="Confirm!"  ID ="Button2" >
    
</ body >
</ HTML >

你可能感兴趣的:(JavaScript,html,function,input,div,button)