欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript Demo模態(tài)窗口

 更新時(shí)間:2009年12月06日 00:47:20   作者:  
不多介紹了,應(yīng)該見(jiàn)很多了,見(jiàn)過(guò)很多網(wǎng)站用的是Jquery的插件,個(gè)人覺(jué)得不夠靈活。
下面這個(gè)Demo支持回調(diào),可以直接引用modalDialog.js使用,不存在任何Jquery的影子
global.js
復(fù)制代碼 代碼如下:

window.js = new myJs(); //為了避免名稱(chēng)重復(fù)我們換個(gè)名稱(chēng),附加一個(gè)myJs對(duì)像到window對(duì)象上,然后我們?cè)陧?yè)面中調(diào)用window.js
//js對(duì)象
function myJs() {
this.x = 10;
}
//下面我們對(duì)myJs進(jìn)行擴(kuò)展
myJs.prototype.alert = function (msg) { alert(msg); } //一個(gè)alert方法測(cè)試調(diào)用js.alert('彈出提示');
//獲取制定Id的dom對(duì)象
myJs.prototype.$ = function (id) { return document.getElementById(id); }
myJs.prototype.bodyWidth = document.documentElement.clientWidth;
myJs.prototype.bodyHeight = document.documentElement.clientHeight;
myJs.prototype.body = document.body;

modalDialog.js 文件代碼如下:
代碼
復(fù)制代碼 代碼如下:

//Modaldialog
function modalDialog() {
this.uri ="about:blank"; //地址
this.title = null; //標(biāo)題
this.width = 400; //默認(rèn)寬
this.height = 300; //默認(rèn)高
this.borderColor = "black"; //邊框顏色
this.borderWidth = 2; //邊框?qū)挾?
this.callback = null; //回調(diào)方法
this.background = "black";
this.titleBackground = "silver";
}
modalDialog.prototype.url = this.uri; //這樣不用擴(kuò)展也是可以的但是在頁(yè)面中只能提示找不到這個(gè)屬性
modalDialog.prototype.title = this.title;
modalDialog.prototype.width = this.width;
modalDialog.prototype.height = this.height;
modalDialog.prototype.background = this.background;
modalDialog.prototype.borderWidth = this.borderWidth;
modalDialog.prototype.borderColor = this.borderColor;
modalDialog.prototype.titleBackground = this.titleBackground;
modalDialog.prototype.callback = this.callback;
//觸發(fā)回調(diào)方法
modalDialog.prototype.call = function (callback) { if (callback != null) callback(this); if (this.callback != null) this.callback(); }
//顯示
modalDialog.prototype.show = function () {
var js = window.js;
//在里面實(shí)現(xiàn)顯示的細(xì)節(jié)
var x = js.bodyWidth, y = js.bodyHeight;
//先創(chuàng)建一個(gè)層遮罩整個(gè)body
var zdiv = "zdiv"; //遮罩層id
document.body.innerHTML += "<div id='" + zdiv + "' style='width:" + x + "px;height:" + y + "px;background-color:" +
this.background + ";position:absolute;top:0;left:0;" +
"filter:alpha(opacity=80);opacity:0.8;z-index:'></div>";
var mdiv = "mdiv"; //模態(tài)窗口層id
document.body.innerHTML += "<div id='" + mdiv + "' style='width:" + this.width + "px;height:" + this.height + "px;" +
"border:solid " + this.borderWidth + "px " + this.borderColor + ";z-index:20;position:absolute;top:" +
(y - this.height) / 2 + ";left:" + (x - this.width) / 2 + ";'>" +
//加上標(biāo)題
(this.title != null ? "<div style='background:" + this.titleBackground + ";line-height:30px;padding:0 10px;width:100%'>" + this.title + "</div>" : "") +
"<div style='padding:1px;'><iframe src='" + this.uri + "' frameborder='0' scrolling='no' style='width:" + (this.width) + "px;height:" +
(this.title != null ? this.height - 30 : this.height) + "px;'></iframe></div></div>";
}
modalDialog.prototype.close = function () {
document.body.removeChild(window.js.$("mdiv"));
document.body.removeChild(window.js.$("zdiv"));
}

default.html 頁(yè)面上創(chuàng)建modalDialog
代碼
復(fù)制代碼 代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>模態(tài)窗口Demo</title>
<!--下面這個(gè)js文件為我們的公共js文件-->
<script type="text/javascript" src="global.js"></script>
<!--ModalDialog UI js文件-->
<script type="text/javascript" src="modaldialog.js"></script>
<script type="text/javascript">
var md; //用于頁(yè)面回調(diào)
var uri = "/test.html";
function showModalDialog() {
//處理打開(kāi)模態(tài)窗口
var m = new modalDialog();
m.uri = uri;
m.title = "模態(tài)窗口";
m.background = "white";
m.borderColor = "orange";
m.borderWidth = 2;
m.titleBackground = "gold";
m.callback = function () { m.close(); }
// m.call(); 這個(gè)回調(diào)方法在modalDialog的Uri中調(diào)用
m.show();
md = m;
}
</script>
</style>
</head>
<body>
<div>
用javascript+css實(shí)現(xiàn)ModalDialog<br />
Jquery框架里面有個(gè)插件也可以實(shí)現(xiàn)這種效果,不過(guò)我們說(shuō)的是自己實(shí)現(xiàn)
<br />
<input id="btopenDialog" type="button" value="打點(diǎn)模態(tài)窗口!" onclick="showModalDialog()" />
</div>
</body>
</html>

在modalDialog頁(yè)面中使用window.parent.md.call()觸發(fā)回調(diào)函數(shù)
文件打包腳本之家下載

相關(guān)文章

  • JavaScript簡(jiǎn)單驗(yàn)證表單空值及郵箱格式的方法

    JavaScript簡(jiǎn)單驗(yàn)證表單空值及郵箱格式的方法

    這篇文章主要介紹了JavaScript簡(jiǎn)單驗(yàn)證表單空值及郵箱格式的方法,涉及javascript基本的表單與字符串操作相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2017-01-01
  • JavaScript代碼輕松實(shí)現(xiàn)網(wǎng)頁(yè)內(nèi)容禁止復(fù)制(代碼簡(jiǎn)單)

    JavaScript代碼輕松實(shí)現(xiàn)網(wǎng)頁(yè)內(nèi)容禁止復(fù)制(代碼簡(jiǎn)單)

    有些時(shí)候我們寫(xiě)的內(nèi)容不想被別人復(fù)制,在代碼中怎么實(shí)現(xiàn)的呢?下面小編給大家介紹javascript代碼輕松實(shí)現(xiàn)網(wǎng)頁(yè)內(nèi)容禁止復(fù)制,感興趣的童鞋一起看看吧
    2015-10-10
  • require.js中的define函數(shù)詳解

    require.js中的define函數(shù)詳解

    這篇文章主要給大家介紹了關(guān)于require.js中define函數(shù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用require.js中的define函數(shù)具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-07-07
  • 利用Echarts如何實(shí)現(xiàn)多段圓環(huán)圖

    利用Echarts如何實(shí)現(xiàn)多段圓環(huán)圖

    這篇文章主要給大家介紹了關(guān)于利用Echarts如何實(shí)現(xiàn)多段圓環(huán)圖的相關(guān)資料,文中通過(guò)實(shí)例代碼代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-03-03
  • typescript中聲明合并介紹

    typescript中聲明合并介紹

    這篇文章主要介紹了typescript中聲明合并介紹,類(lèi)型合并表明編譯器將合并兩個(gè)分開(kāi)的并且名稱(chēng)相同的聲明,合并之后的聲明擁有兩個(gè)聲明的特點(diǎn),任意數(shù)量的聲明可以被合并,不僅限兩個(gè),更多相關(guān)內(nèi)容需要的朋友可以參考下面文章內(nèi)容
    2022-09-09
  • javascript 響應(yīng)鍵盤(pán)特定按鍵(只響應(yīng)數(shù)字鍵)

    javascript 響應(yīng)鍵盤(pán)特定按鍵(只響應(yīng)數(shù)字鍵)

    響應(yīng)鍵盤(pán)特定按鍵(只響應(yīng)數(shù)字鍵),大家可以看看思路。
    2009-03-03
  • JavaScript必知必會(huì)(九)function 說(shuō)起 閉包問(wèn)題

    JavaScript必知必會(huì)(九)function 說(shuō)起 閉包問(wèn)題

    這篇文章主要介紹了JavaScript必知必會(huì)(九)function 說(shuō)起 閉包問(wèn)題的相關(guān)資料,需要的朋友可以參考下
    2016-06-06
  • 淺談Layui的eleTree樹(shù)式選擇器使用方法

    淺談Layui的eleTree樹(shù)式選擇器使用方法

    今天小編就為大家分享一篇淺談Layui的eleTree樹(shù)式選擇器使用方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-09-09
  • javascript快速排序算法詳解

    javascript快速排序算法詳解

    JavaScript實(shí)現(xiàn)的常見(jiàn)排序算法有:冒泡排序,選擇排序,插入排序,謝爾排序,快速排序(遞歸),快速排序(堆棧),歸并排序,堆排序。今天我們來(lái)詳細(xì)分析下快速排序算法
    2014-09-09
  • JS等比例縮小圖片尺寸的實(shí)例

    JS等比例縮小圖片尺寸的實(shí)例

    JS等比例縮小圖片尺寸的實(shí)例,需要的朋友可以參考一下
    2013-02-02

最新評(píng)論