天天看點

仿163彈出層

<script language="javascript">

/**

 * 功能:顯示提示視窗

 * 作者:申楠 qq:38371354 email:[email protected] http;//amushen.cnblogs.com

 * 日期:2005-10-26

 * 版本:1.1

 * 備注:版權沒有,随便拷貝,如果用于商業應用請通知本人,同時保留這段注釋。

 *

 */

 /**

  * 改造:黑旋風 qq:23929003 email:[email protected]

  * 日期:2006-03-17

  * 版本:1.2

  * 說明:本人在申楠同志的《顯示提示視窗》基礎上,将

  */

var alternateframe=null;//生成的iframe

var alternatewin=null;

window.alert=showalert;

window.confirm=showconfirm;

 * 人機互動視窗,覆寫自帶的

function alternatewindow(){

this.win=null;//生成對話框的視窗對象

this.pbody=null;//生成的body容器對象

this.pbg=null;

this.type="alert";//預設的種類是alert

this.focuswhere="ok";//焦點在哪個按鈕上

}

 * 模仿的alert視窗

function showalert(info){

alternatewin=new alternatewindow();

var pbody = alternatewin.init();

alternatewin.initalertbody(pbody,info);

alternatewin.type="alert";

  /**

function showconfirm(info,ok_func,notok_func,ok_str,not_okstr){

alternatewin.initconfirmbody(pbody,info,ok_func,notok_func,ok_str,not_okstr);

alternatewin.type="confirm";

 * 作用:初始基本資訊

alternatewindow.prototype.init=function() {

if(alternateframe==null){

alternateframe=document.createelement("<iframe allowtransparency='true' id='popframe' frameborder=0 marginheight=0 src='about:blank' marginwidth=0 hspace=0 vspace=0 scrolling=no></iframe>")

alternateframe.style.position="absolute";

document.body.appendchild(alternateframe);

}else{

alternateframe.style.visibility="visible";

alternateframe.style.width=screen.availwidth;

alternateframe.style.height=screen.availheight;

alternateframe.style.left=document.body.scrollleft;

alternateframe.style.top=document.body.scrolltop;

alternateframe.name=alternateframe.uniqueid;

this.win=window.frames[alternateframe.name];

this.win.document.write("<body leftmargin=0 topmargin=0 oncontextmenu='self.event.returnvalue=false'><div id=popbg></div><div id=popbody></div><div></div></body>");

this.win.document.body.style.backgroundcolor="transparent";

document.body.style.overflow="hidden";

this.pbody=this.win.document.body.children[1];

this.pbg=this.win.document.body.children[0];

this.hideallselect();

this.initbg();

return this.pbody;

* 作用:初始化背景層

alternatewindow.prototype.initbg=function(){

with(this.pbg.style){

position="absolute";

left="0";

top="0";

width="100%";

height="100%";

visibility="hidden";

backgroundcolor="#333333";

filter="blendtrans(duration=1) alpha(opacity=30)";

this.pbg.filters.blendtrans.apply();

this.pbg.style.visibility="visible";

this.pbg.filters.blendtrans.play();

 * 作用:初始化顯示層

alternatewindow.prototype.initalertbody=function(obj,info){

with(obj.style){

width="400";

height="150";

backgroundcolor="#ffffff";

obj.style.left=window.document.body.clientwidth/2-200;

obj.style.top=window.document.body.clientheight/3;

var str;

str ="<table border=0 cellpadding=0 cellspacing=1 bgcolor=#000000 width=100% height=100%><tr height=30>";

str+="<td align=left style='color:#000000;font-size:14px;font-weight:bold' bgcolor=#9999ff>[提示]</td></tr>";

str+="<tr><td align=center bgcolor=#efefff style='font-size:12px;color:#000000;vertical-align: middle;'>";

str+=info+"</td></tr><tr height=30 bgcolor=#efefef><td align=center>" +

     "<input type='button' value='确定' id='ok'" +

     " onkeydown='parent.alternatewin.onkeydown(event,this)'"+

     " onclick='parent.alternatewin.closewin()' style='border:solid 1px #666666;background:#cccccc'>" +

     "</td></tr></table>";

obj.innerhtml=str;

this.win.document.body.all.ok.focus();

this.focuswhere="ok";

alternatewindow.prototype.onkeydown=function(event,obj){

  switch(event.keycode){

  case 9:

   event.keycode=-1;

  if(this.type=="confirm"){

  if(this.focuswhere=="ok"){

  this.win.document.body.all.no.focus();

  this.focuswhere="no";

  }else{

  this.win.document.body.all.ok.focus();

  this.focuswhere="ok";

  }

  break;

  case 13:obj.click();;break;

  case 27:this.closewin();break; 

 * 作用:初始化顯示層 confirm提示層

alternatewindow.prototype.initconfirmbody=function(obj,info,ok_func,notok_func,ok_str,notok_str){

if(ok_str==null){

ok_str="确定";

if(notok_str==null){

notok_str="取消"

str="<table border=0 cellpadding=0 cellspacing=1 bgcolor=#000000 width=100% height=100%><tr height=30>";

str+="<td align=left style='color:#000000;font-size:14px;font-weight:bold' bgcolor=#9999ff>[詢問]</td></tr>";

"<input type='button' id='ok'" +

" onkeydown='parent.alternatewin.onkeydown(event,this)'"+

" onclick='parent.alternatewin.closewin();parent."+ok_func+"();' " +

" value='"+ok_str+"' style='border:solid 1px #666666;background:#cccccc'>"+

"   <input type='button' value='"+notok_str+"' id='no'"+

" onclick='parent.alternatewin.closewin();" +

" parent."+notok_func+"();' style='border:solid 1px #666666;background:#cccccc'></td></tr></table>";

 * 作用:關閉一切

alternatewindow.prototype.closewin=function(){

alternateframe.style.visibility="hidden";

this.showallselect();

document.body.style.overflow="auto";

  * 作用:隐藏所有的select

alternatewindow.prototype.hideallselect=function(){

  var obj;

  obj=document.getelementsbytagname("select");

  var i;

  for(i=0;i<obj.length;i++)

obj[i].style.visibility="hidden";

 * 顯示所有的select

 */ 

  alternatewindow.prototype.showallselect=function(){

obj[i].style.visibility="visible";

</script>

<!---------------------------------------------------------------->

<script>

function clk_yes(){

alert("你也同意了我的觀點");

function clk_no(){

alert("不是你眼花了就是我眼花了!");

<body>

<button onclick="alert('我覺得今天天氣真的很不錯!')">test</button>

<button onclick="confirm('今天天氣真的很好啊,難道不是麼?','clk_yes','clk_no','就算是吧','亂講')">詢問框測試</button>

<p><br/>

  <br/>

彈出提示的音效檔案是:snd.mp3</p>

<p>如果需要可以替換成其它檔案,檔案名要設定成snd.mp3</p>

<p>版本1.2修改:<br/>

  1、主要修改了滾屏出現的問題

</p>

<p>版本1.1修改:<br/>

  1、增加了詢問框的功能。<br/>

  2、增加了音效功能<br/>

  3、修飾界面</p>

<p><b>黑旋風(lckking)mail:[email protected] qq:23929003</b><br/>版本1.2修改:<br/>

由于最近在做一個東西,需要對界面設計的很友好,是以借用了你的源代碼,但是你的作品還有些bug以及不足,<br/>

例如alert之後如果按tab鍵,焦點會回到首頁面上去,這樣就不安全了。聲音加載的時候,頁面會閃一下,<br/>

也不是很好,詢問框按鈕文字windows的沒法改,難道自己模拟的也沒法改嗎?(當然,我把他改了)。<br/>

同原作一樣,沒考慮跨浏覽器,以後有機會再改了<br/>

對了,你的函數上原來的那些注釋(如:日期、作者等)寫得那麼多,看程式覺得不友善,就删除了,不要介意!<br/>

總之謝謝了,為了感謝網友的無私,我也把改了的代碼發給大家,希望對大家有所幫助,獻醜了!<br/>

  1、由于聲音加載會使頁面跳一下,我不太喜歡,去掉了這個功能,希望不要介意。<br/>

  2、改成面向對象設計,這樣更加合理一點(個人意見)<br/>

  3、擴充了詢問框的按鈕文字參數設定<br/>

  4、覆寫了系統自帶的alert和confirm方法,如果大家不喜歡,把頭上那2句話删除就可以了<br/>

  5、支援鍵盤操作。</p>

</body>