源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

利用javascript打开模态对话框(示例代码)

  • 时间:2020-01-25 10:58 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:利用javascript打开模态对话框(示例代码)
[b]1. 标准的方法 [/b]
[u]复制代码[/u] 代码如下:
<script type="text/javascript">   function openWin(src, width, height, showScroll){   window.showModalDialog (src,"","location:No;status:No;help:No;dialogWidth:"+width+";dialogHeight:"+height+";scroll:"+showScroll+";");   }   </script> 
例:<span style="CURSOR: pointer" onclick="openWin  ('http://www.1sucai.cn', '500px', '400px', 'no')">点击</span>  [b]2. 要注意的是,Firefox并不支持该功能,它支持的语法是 [/b] window.open  ('openwin.html','newWin', 'modal=yes, width=200,height=200,resizable=no, scrollbars=no' );  [b]3. 如何自动判断浏览器 [/b]
[u]复制代码[/u] 代码如下:
<input type="button" value="打开对话框" onclick="showDialog('#')"/>    <SCRIPT   LANGUAGE="JavaScript">    <!--    function   showDialog(url)    {     if(   document.all   ) //IE     {     feature="dialogWidth:300px;dialogHeight:200px;status:no;help:no";     window.showModalDialog(url,null,feature);     }     else     {       //modelessDialog可以将modal换成dialog=yes     feature ="width=300,height=200,menubar=no,toolbar=no,location=no,";     feature+="scrollbars=no,status=no,modal=yes";       window.open(url,null,feature);     }    }    //-->  </SCRIPT>
[b]4. 在IE中,模态对话框会隐藏地址栏,而在其他浏览器则不一定[/b] [img]http://files.jb51.net/file_images/article/201401/201401110934472.png[/img] [img]http://files.jb51.net/file_images/article/201401/201401110934473.png[/img] 【注意】在谷歌浏览器中,这个模态的效果也会失效。 [b]5. 一般在弹出对话框的时候,我们都希望整个父页面的背景变为一个半透明的颜色,让用户看到后面是不可以访问的 [/b] [img]http://files.jb51.net/file_images/article/201401/201401110934474.png[/img] 而关闭对话框之后又希望还原 [img]http://files.jb51.net/file_images/article/201401/201401110934475.png[/img] [b]这是怎么做到的呢? [/b]
[u]复制代码[/u] 代码如下:
        ///显示某个订单的详细信息,通过一个模态对话框,而且屏幕会变颜色         function ShowOrderDetails(orderId) {             var url = "details.aspx?orderID=" + orderId; //            $("body").css("filter", "Alpha(Opacity=20)");             //filter:Alpha(Opacity=50)             $("body").addClass("body1");             ShowDetailsDialog(url, "600px", "400px", "yes");             $("body").removeClass("body1");         }
另外,有一个样式表定义 .body1 {     background-color:#999999;     filter:Alpha(Opacity=40); }
[u]复制代码[/u] 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title></title>     <style type="text/css">     .body1{         background-color:#999999;         filter:Alpha(Opacity=40);     }     </style>     <script src="jquery.js" type="text/javascript"></script>     <script type="text/javascript">         function ShowDetailsDialog(src, width, height, showScroll) {             window.showModalDialog(src, "", "location:No;status:No;help:NO;dialogWidth:" + width + ";dialogHeight:" + height + ";scroll" + showScroll + ";");         }         function ShowOrderDetails(orderId) {             var url = 'Details.aspx?orderID=' + orderId;             $("body").addClass("body1");             ShowDetailsDialog(url, '500px', '400px', 'no');             $("body").removeClass("body1");         }     </script> </head> <body>     <form id="form1" runat="server">     <div>     <span style="cursor:pointer" onclick="ShowOrderDetails(11)" >点击</span>     </div>     </form> </body> </html>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部