请问js怎么实现上面的弹出框  

解决方案 »

  1.   

    http://www.jb51.net/article/22680.htm
    http://blog.csdn.net/tolys/article/details/2338640
      

  2.   

    http://www.jb51.net/article/22680.htm
    我照这个例子做了一个  
            divDialog.appendChild(divContent);
            var closeButton = document.createElement("img");
            closeButton.style.cursor = "hand";
            closeButton.setAttribute("src", springweb_basePath + "/images/okButton.png");
            closeButton.setAttribute("alt", "确定");
            
            //the click event when the dialog is closing.
            closeButton.onclick = function() {            document.body.removeChild(divBackground);
                document.body.removeChild(divDialog);
                document.body.style.overflowY = "";
            };
            
            var cancelButton = document.createElement("img");
            cancelButton.style.cursor = "hand";
            cancelButton.setAttribute("src", springweb_basePath + "/images/cancelButton.png");
            cancelButton.setAttribute("alt", "取消");
            
            cancelButton.onclick = function() {            document.body.removeChild(divBackground);
                document.body.removeChild(divDialog);
                document.body.style.overflowY = "";            
            };        怎么实现 按这2个不同的按纽  返回不同的值
    我在调用页面要用 if (richAlert("请再次确认 姓名:张三", "确认框",moveable))
      

  3.   

    弄两个message提示,点击那个弹出的时候就给那个赋这个message值!
      

  4.   

    我在jsp里 
              function showDialog() {
                   var moveable= true;
                    var xsc='请再次确认信息'+"<br /><br />"+'\n\r用户姓名:张3';
                  if( richAlert(xsc, "水费缴费确认框",moveable)==1)              
                     alert("确定");
                  else
                    alert("取消");
    为什么会在显示对话框前就弹出 “确定” 了?
      

  5.   


    /**
     * @see 询问提示框(可代替confirm弹框)
     * @param title 提示框的标题
     * @param winWidth 提示框的宽度
     * @param winHeight 提示框的高度
     * @param message 提示框的内容
     * @param callback 回调函数
     */
    function confirmWin(title, winWidth, winHeight, message, callback) {
    if (getO("divConfirmWin") == null) {
    var newDiv = document.createElement("div");
    newDiv.setAttribute("id", "divConfirmWin");
    newDiv.style.zIndex = 10;
    newDiv.style.border = "2px solid #33CCFF";
    newDiv.style.position = "absolute";
    newDiv.style.backgroundColor = "#FFFFFF";
    newDiv.style.fontSize = "12px";
    newDiv.style.display = "none";
    if (document.form1 != null) {
    document.form1.appendChild(newDiv);
    } else {
    if (getO("form1") != null) {
    getO("form1").appendChild(newDiv);
    } else {
    document.body.appendChild(newDiv);
    }
    }
    var info = "<div align=\"left\" id=\"divConfirmTitle\" style=\"background-color:#33CCFF;height:20px;padding-top:2px;cursor:move;\" onmousedown=\"mousePlead1(event,'divConfirmWin')\"></div>";
    info += "<div align=\"center\" id=\"divConfirmMsg\" style=\"padding-top:8px;padding-left:10px;padding-right:10px;\"></div>";
    info += "<div align=\"center\" id=\"divCloseConfrim\" style=\"border-top:1px solid #33CCFF;height:30px;padding-top:6px;\"></div>";
    fullDiv("divConfirmWin", info);
    }
    var width = parseInt(document.documentElement.clientWidth);
    var height = parseInt(document.documentElement.clientHeight);
    getO("divConfirmWin").style.left = ((width - 240) / 2) + "px";
    getO("divConfirmWin").style.top = ((height - winHeight) / 2) + "px";
    getO("divConfirmWin").style.width = winWidth + "px";
    fullDiv("divConfirmTitle", "&nbsp;&nbsp;<strong><font color=\"#FFFFFF\">" + title + "</font></strong>");
    var info = "<a href=\"javascript:clearConfirm();" + callback + "\"><img src=\"" + getV("hdfPath") + icon_folder + "btnConfirm.jpg.${suffix}\" border=\"0\"/></a>&nbsp;&nbsp;<a id=\"btnCloseConfrim\" href=\"javascript:clearConfirm()\"><img src=\"" + getV("hdfPath") + icon_folder + "btnCancel.jpg.${suffix}\" border=\"0\"/></a>";
    fullDiv("divCloseConfrim", info);
    getO("divConfirmMsg").style.height = (winHeight - 52) + "px";
    fullDiv("divConfirmMsg", "<img src=\"" + getV("hdfPath") + icon_folder + "ask.gif.${suffix}\"/> " + message);
    setEnvelopDiv();
    showSelects("0");
    showDiv("divConfirmWin", "1");
    }
    function clearConfirm() {
    showDiv("divEnvelop", "0");
    showDiv("divConfirmWin", "0");
    showSelects("1");
    }/**
    * @see 获得对象
    * @param id 对象的id(表单元素和其他标签都可以)
    * @return Object
    */
    function getO(id) {
    return document.getElementById(id);
    }/**
    * @see 给div设置普通内容(其他标签也可以)
    * @param id 层的id或其他标签的id
    * @param content 将要设置的内容
    */
    function fullDiv(id, content) {
    if (getO(id) != null) {
    getO(id).innerHTML = content;
    } else {
    alert(id + "\u672a\u5b9a\u4e49");
    }
    }/**
     * @see 设置一个遮盖的Div,它的z-index为3
     */
    function setEnvelopDiv() {
    if (getO("divEnvelop") == null) {
    var newDiv = document.createElement("div");
    newDiv.setAttribute("id", "divEnvelop");
    newDiv.style.position = "absolute";
    newDiv.style.zIndex = 3;
    newDiv.style.backgroundColor = "#738E9D";
    newDiv.style.left = "0px";
    newDiv.style.top = "0px";
    newDiv.style.width = getWinSize()[0] + "px";
    newDiv.style.height = getWinSize()[1] + "px";
    newDiv.style.filter = "alpha(opacity=15)";
    newDiv.style.opacity = "0.1";
    newDiv.style.display = "none";
    document.body.appendChild(newDiv);
    }
    showDiv("divEnvelop", "1");
    }/**
    * @see 设置div的显示或隐藏(其他元素也可以)
    * @param id 层的id或其他元素的id
    * @param type 1为显示0为隐藏
    */
    function showDiv(id, type) {
    if (getO(id) != null) {
    var status = ("1" == type) ? "block" : "none";
    getO(id).style.display = status;
    }
    }/**
     * @see 隐藏或显示所有的下拉框
     * @param type 1表示显示,0表示隐藏
     */
    function showSelects(type) {
    var status = (type == "1") ? "visible" : "hidden";
    var boxs = document.getElementsByTagName("SELECT");
    for (var i = 0; i < boxs.length; i++) {
    boxs[i].style.visibility = status;
    }
    }/**
     * @see 获得当前窗体的大小(width,height)
     * @return Array 
     */
    function getWinSize() {
    var width = parseInt(document.documentElement.clientWidth);
    var height = parseInt(document.documentElement.clientHeight);
    return new Array(width, height);
    }
    可能还有代码没复制到,另外需要几张图片,
    经过这样处理后,浏览器的原始弹框都不会再出现了,
      

  6.   

    Quote: 引用 10 楼 s478853630 的回复:

    可能还有代码没复制到,另外需要几张图片,
     经过这样处理后,浏览器的原始弹框都不会再出现了,
    /quote]
    我调用 confirmWin 没反映 
      

  7.   

    给你看个更简单的东西:点击出触发按钮事件的时候,你只要给出你的提示内容就ok!你把代码粘到html里面试一下,效果很好!<html> 
    <head> 
    <title>JS弹出一个网页对话框,后面全变灰,并不可用。</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <style type="text/css"> 
    *{margin:0;padding:0;} 
    </style> 
    </head> 
    <body> 
    JS弹出一个网页对话框,后面全变灰,并不可用。思路:一个覆盖整个页面的层,设置透明度0 
        <p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p> 
        <p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p> 
        <input type="button" value="点击这里" onClick="sAlert('测试效果<br/>嗯!效果还不错!');" /> 
        
    <script type="text/javascript" language="javascript"> 
    function sAlert(str){ 
    var msgw,msgh,bordercolor; 
    msgw=400;//提示窗口的宽度 
    msgh=100;//提示窗口的高度 
    titleheight=25//提示窗口标题高度 
    bordercolor="#336699";//提示窗口的边框颜色 
    titlecolor="#99CCFF";//提示窗口的标题颜色 
    var sWidth,sHeight; 
    sWidth=document.body.offsetWidth;//浏览器工作区域内页面宽度 或使用 screen.width//屏幕的宽度 
    sHeight=screen.height;//屏幕高度(垂直分辨率) 
    //背景层(大小与窗口有效区域相同,即当弹出对话框时,背景显示为放射状透明灰色) 
    var bgObj=document.createElement("div");//创建一个div对象(背景层) //动态创建元素,这里创建的是 div 
    //定义div属性,即相当于(相当于,但确不是,必须对对象属性进行定义 
    //<div id="bgDiv" style="position:absolute; top:0; background-color:#777; filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75); opacity:0.6; left:0; width:918px; height:768px; z-index:10000;"></div> 
    bgObj.setAttribute('id','bgDiv'); 
    bgObj.style.position="absolute"; 
    bgObj.style.top="0"; 
    bgObj.style.background="#777"; 
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
    bgObj.style.opacity="0.6"; 
    bgObj.style.left="0"; 
    bgObj.style.width=sWidth + "px"; 
    bgObj.style.height=sHeight + "px"; 
    bgObj.style.zIndex = "10000"; 
    document.body.appendChild(bgObj);//在body内添加该div对象 
    //创建一个div对象(提示框层) 
    var msgObj=document.createElement("div") 
    //定义div属性,即相当于 
    //<div id="msgDiv" align="center" style="background-color:white; border:1px solid #336699; position:absolute; left:50%; top:50%; font:12px/1.6em Verdana,Geneva,Arial,Helvetica,sans-serif; margin-left:-225px; margin-top:npx; width:400px; height:100px; text-align:center; line-height:25px; z-index:100001;"></div> 
    msgObj.setAttribute("id","msgDiv"); 
    msgObj.setAttribute("align","center"); 
    msgObj.style.background="white"; 
    msgObj.style.border="1px solid " + bordercolor; 
    msgObj.style.position = "absolute"; 
    msgObj.style.left = "50%"; 
    msgObj.style.top = "50%"; 
    msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 
    msgObj.style.marginLeft = "-225px" ; 
    msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px"; 
    msgObj.style.width = msgw + "px"; 
    msgObj.style.height =msgh + "px"; 
    msgObj.style.textAlign = "center"; 
    msgObj.style.lineHeight ="25px"; 
    msgObj.style.zIndex = "10001"; 
    var title=document.createElement("h4");//创建一个h4对象(提示框标题栏) 
    //定义h4的属性,即相当于 
    //<h4 id="msgTitle" align="right" style="margin:0; padding:3px; background-color:#336699; filter:progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100); opacity:0.75; border:1px solid #336699; height:18px; font:12px Verdana,Geneva,Arial,Helvetica,sans-serif; color:white; cursor:pointer;" onclick="">关闭</h4> 
    title.setAttribute("id","msgTitle"); 
    title.setAttribute("align","right"); 
    title.style.margin="0"; 
    title.style.padding="3px"; 
    title.style.background=bordercolor; 
    title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);"; 
    title.style.opacity="0.75"; 
    title.style.border="1px solid " + bordercolor; 
    title.style.height="18px"; 
    title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif"; 
    title.style.color="white"; 
    title.style.cursor="pointer"; 
    title.innerHTML="关闭"; 
    title.onclick=removeObj; 
    var button=document.createElement("input");//创建一个input对象(提示框按钮) 
    //定义input的属性,即相当于 
    //<input type="button" align="center" style="width:100px; align:center; margin-left:250px; margin-bottom:10px;" value="关闭"> 
    button.setAttribute("type","button"); 
    button.setAttribute("value","关闭"); 
    button.style.width="60px"; 
    button.style.align="center"; 
    button.style.marginLeft="250px"; 
    button.style.marginBottom="10px"; 
    button.style.background=bordercolor; 
    button.style.border="1px solid "+ bordercolor; 
    button.style.color="white"; 
    button.onclick=removeObj; 
    function removeObj(){//点击标题栏触发的事件 
       document.body.removeChild(bgObj);//删除背景层Div 
       document.getElementById("msgDiv").removeChild(title);//删除提示框的标题栏 
       document.body.removeChild(msgObj);//删除提示框层 

    document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj 
    document.getElementById("msgDiv").appendChild(title);//在提示框div中添加标题栏对象title 
    var txt=document.createElement("p");//创建一个p对象(提示框提示信息) 
    //定义p的属性,即相当于 
    //<p style="margin:1em 0;" id="msgTxt">测试效果</p> 
    txt.style.margin="1em 0" 
    txt.setAttribute("id","msgTxt"); 
    txt.innerHTML=str;//来源于函数调用时的参数值 
    document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt 
    document.getElementById("msgDiv").appendChild(button);//在提示框div中添加按钮对象button 

    </script> 
    </body> 
    </html>
      

  8.   

    来个简单点的吧
    // 弹出一个信息对话框.
    function infoMessage(text){
    $.prompt(text_info(text),{buttons:{'确认':true}});
    }
    // 封装信息消息文本.
    function text_info(text){
    return "<table><tr><td><img src='img/information.png'></td><td valign='middle'><B>" + text + "</B></td></tr></table>";
    }
    需要引入jquery   
      

  9.   

    用jquery的,现成框架的,不出错,效果还好看
      

  10.   

    // 弹出一个错误对话框.
    function wrongMessage(text){
    $.prompt(text_wrong(text),{buttons:{'确认':true}});
    }
    // 封装错误消息文本.
    function text_wrong(text){
    return "<table><tr><td><img src='img/information.png'></td><td valign='middle'><B>" + text + "</B></td></tr></table>";
    }
    // 弹出一个询问对话框.
    function showConfirm(text,callbackfunc){
    $.prompt(message(text),{buttons:{'确认':true,'取消':false},callback:callbackfunc,focus:1});
    }
    // 封装询问对话框消息文本.
    function message(text){
    return "<table><tr><td><img src='img/confirm.png'></td><td valign='middle'><B>" + text + "</B></td></tr></table>";
    }
      

  11.   

    你这个判断里面的东西返回的是什么,是true或者false?
      

  12.   

    看到尼玛这么多的代码蛋疼
    哥送你个jueqry写的弹出窗!!!
    function showMsg(content, left,isbody,diyCss){
    var msg = '';
    msg += "<div class=\"tc_content\">";
    msg += "<div class=\"tc_text font_grays\">"+content+"</div>";
    msg += "<div class=\"tc_btn\"><a href=\"#\" class=\"button \" onclick=\"myclose();\">关闭</a>";
    msg += "<div class=\"tc_content\">";
    msg += "<div class=\"tc_content\">";
    msg += "<div class=\"tc_content\">";
    msg += "</div>"; //给你要弹的组件id绑定一个窗户弹出事件
    $(id).block({ 
    message: msg,
    theme:true,
    showOverlay:true, 
    draggable: false,
    baseZ:1000+1,
    title:"<font style='color: white;'>提示</font>",
    themedCSS: getCss
    });

            }
      

  13.   


                Ext.Msg.show({
                    title: 'Milton',
                    msg: 'Have you seen my stapler?',
                    buttons: {"OK":"这是OK","NO":"这是NO","Cancel":"这是Cancel"}
                });
    还是这个代码更精简
      

  14.   

    div+css 
    用js控制div,用css美化div
      

  15.   

    百度查询 easyDialog v2.0 这个做弹出层挺简单的,以前一个项目我用了
    全中文api
    简单,快捷,方便~! 哈哈其他的一些很不错的弹出层插件
    fancybox
    artDialog
    thickbox
    等等 不全部举例啦
      

  16.   

    省事一点的话就去找jquery的插件,漂亮又实用
      

  17.   

    var telephone = 15924019932;
    var data = 10;
    if(!confirm("您确定为"+telphone+"充值"+data+"元吗?")){
       return false;
    }