利用javascript打開模態(tài)對(duì)話框(示例代碼)
1. 標(biāo)準(zhǔn)的方法
<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.dbjr.com.cn', '500px', '400px', 'no')">點(diǎn)擊</span>
2. 要注意的是,F(xiàn)irefox并不支持該功能,它支持的語法是
window.open
('openwin.html','newWin', 'modal=yes, width=200,height=200,resizable=no, scrollbars=no' );
3. 如何自動(dòng)判斷瀏覽器
<input type="button" value="打開對(duì)話框" 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>
4. 在IE中,模態(tài)對(duì)話框會(huì)隱藏地址欄,而在其他瀏覽器則不一定
【注意】在谷歌瀏覽器中,這個(gè)模態(tài)的效果也會(huì)失效。
5. 一般在彈出對(duì)話框的時(shí)候,我們都希望整個(gè)父頁面的背景變?yōu)橐粋€(gè)半透明的顏色,讓用戶看到后面是不可以訪問的
而關(guān)閉對(duì)話框之后又希望還原
這是怎么做到的呢?
///顯示某個(gè)訂單的詳細(xì)信息,通過一個(gè)模態(tài)對(duì)話框,而且屏幕會(huì)變顏色
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");
}
另外,有一個(gè)樣式表定義
.body1
{
background-color:#999999;
filter:Alpha(Opacity=40);
}
<%@ 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)" >點(diǎn)擊</span>
</div>
</form>
</body>
</html>
- JS 模態(tài)對(duì)話框和非模態(tài)對(duì)話框操作技巧匯總
- javascript showModalDialog模態(tài)對(duì)話框使用說明
- JavaScript 實(shí)現(xiàn)模態(tài)對(duì)話框 源代碼大全
- 詳解AngularJS 模態(tài)對(duì)話框
- JS對(duì)話框_JS模態(tài)對(duì)話框showModalDialog用法總結(jié)
- 兩種WEB下的模態(tài)對(duì)話框 (asp.net或js的分別實(shí)現(xiàn))
- js模態(tài)對(duì)話框使用方法詳解
- js實(shí)現(xiàn)div模擬模態(tài)對(duì)話框展現(xiàn)URL內(nèi)容
- ModelDialog JavaScript模態(tài)對(duì)話框類代碼
- JavaScript實(shí)現(xiàn)模態(tài)對(duì)話框?qū)嵗?/a>
- js實(shí)現(xiàn)響應(yīng)按鈕點(diǎn)擊彈出可拖拽的非模態(tài)對(duì)話框完整實(shí)例【測(cè)試可用】
相關(guān)文章
JS跨域之window.name實(shí)現(xiàn)的跨域數(shù)據(jù)傳輸
這篇文章主要介紹了JS跨域之window.name實(shí)現(xiàn)的跨域數(shù)據(jù)傳輸,需要的朋友可以參考下2022-01-01包含中國(guó)城市的javascript對(duì)象實(shí)例
這篇文章主要介紹了包含中國(guó)城市的javascript對(duì)象,以一個(gè)javascript的json數(shù)據(jù)格式存儲(chǔ)為例分析了javascript存儲(chǔ)城市信息的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08實(shí)例分析瀏覽器中“JavaScript解析器”的工作原理
本文主要對(duì)javascript解析器的工作原理進(jìn)行實(shí)例分析,具有很好的參考價(jià)值,下面就跟小編一起來看下吧2016-12-12javascript實(shí)現(xiàn)Table排序的方法
這篇文章主要介紹了javascript實(shí)現(xiàn)Table排序的方法,涉及javascript針對(duì)表格對(duì)象的獲取與排序相關(guān)技巧,需要的朋友可以參考下2015-05-05javascript中的Array對(duì)象(數(shù)組的合并、轉(zhuǎn)換、迭代、排序、堆棧)
Array?是javascript中經(jīng)常用到的數(shù)據(jù)類型。javascript?的數(shù)組其他語言中數(shù)組的最大的區(qū)別是其每個(gè)數(shù)組項(xiàng)都可以保存任何類型的數(shù)據(jù)。本文主要討論javascript中數(shù)組的聲明、轉(zhuǎn)換、排序、合并、迭代等等基本操作2023-03-03