利用javascript打開模態(tài)對話框(示例代碼)
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.fzitv.net', '500px', '400px', 'no')">點擊</span>
2. 要注意的是,F(xiàn)irefox并不支持該功能,它支持的語法是
window.open
('openwin.html','newWin', 'modal=yes, width=200,height=200,resizable=no, scrollbars=no' );
3. 如何自動判斷瀏覽器
<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>
4. 在IE中,模態(tài)對話框會隱藏地址欄,而在其他瀏覽器則不一定


【注意】在谷歌瀏覽器中,這個模態(tài)的效果也會失效。
5. 一般在彈出對話框的時候,我們都希望整個父頁面的背景變?yōu)橐粋€半透明的顏色,讓用戶看到后面是不可以訪問的

而關(guān)閉對話框之后又希望還原

這是怎么做到的呢?
///顯示某個訂單的詳細(xì)信息,通過一個模態(tài)對話框,而且屏幕會變顏色
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);
}
<%@ 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>
- JS 模態(tài)對話框和非模態(tài)對話框操作技巧匯總
- javascript showModalDialog模態(tài)對話框使用說明
- JavaScript 實現(xiàn)模態(tài)對話框 源代碼大全
- 詳解AngularJS 模態(tài)對話框
- JS對話框_JS模態(tài)對話框showModalDialog用法總結(jié)
- 兩種WEB下的模態(tài)對話框 (asp.net或js的分別實現(xiàn))
- js模態(tài)對話框使用方法詳解
- js實現(xiàn)div模擬模態(tài)對話框展現(xiàn)URL內(nèi)容
- ModelDialog JavaScript模態(tài)對話框類代碼
- JavaScript實現(xiàn)模態(tài)對話框?qū)嵗?/a>
- js實現(xiàn)響應(yīng)按鈕點擊彈出可拖拽的非模態(tài)對話框完整實例【測試可用】
相關(guān)文章
JS 實現(xiàn)10進(jìn)制轉(zhuǎn)換36進(jìn)制的示例代碼
這篇文章主要介紹了JS實現(xiàn)10進(jìn)制轉(zhuǎn)換36進(jìn)制,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
input輸入框限制只能輸入數(shù)字的方法實例(個人認(rèn)為最好的)
在很多業(yè)務(wù)中需要對輸入框進(jìn)行字符限制,比如金額輸入框、手機號碼輸入框等,下面這篇文章主要給大家介紹了關(guān)于input輸入框限制只能輸入數(shù)字的相關(guān)資料,文中介紹的方法個人認(rèn)為最好的,需要的朋友可以參考下2022-10-10

