JS新作弹出框
<HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function myAlert(str){
var msgw,msgh,bordercolor;
msgw=400; //提示窗口的宽度
msgh=100; //提示窗口的高度
titleheight=25 //提示窗口标题高度
bordercolor="#336699"; //提示窗口的边框颜色
titlecolor="#99CCFF"; //提示窗口的标题颜色
var sWidth,sHeight; //顶层窗体的宽和高
sWidth=top.document.body.offsetWidth; //遮罩层的宽度
sHeight=top.document.body.offsetHeight; //遮罩层的高度
if(sHeight<top.screen.height)
{
sHeight=top.screen.height; //窗口滚动条位置不在0点,则遮罩层高度为屏幕高度
}
//遮罩层
var bgObj=top.document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#777";
//设置滤镜
bgObj.style.filter="progidXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000";
top.document.body.appendChild(bgObj); //添加进窗口中
//设置消息框的一些属性
var msgObj=top.document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="1px solid " + bordercolor;
msgObj.style.position = "absolute";
msgObj.style.left = "50%";
msgObj.style.top = "50%";
msgObj.style.font="12px 宋体";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+top.document.documentElement.scrollTop+"px";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight = (msgh-titleheight) + "px";
msgObj.style.zIndex = "10001";
//消息框的标题栏
var title=top.document.createElement("h4");
title.setAttribute("id","msgTitle");
title.setAttribute("align","right");
title.style.margin="0";
title.style.padding="3px";
title.style.background=bordercolor;
title.style.filter="progidXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
title.style.opacity="0.75";
title.style.border="1px solid " + bordercolor;
title.style.height="18px";
title.style.font="12px 宋体";
title.style.color="white";
title.style.cursor="pointer";
title.innerText="关闭";
title.onclick=function(){ //单击标题栏,关掉遮罩层
top.document.body.removeChild(bgObj);
top.document.getElementById("msgDiv").removeChild(title);
top.document.body.removeChild(msgObj);
}
top.document.body.style.overflow = "hidden";
top.document.body.appendChild(msgObj); //添加高亮层
top.document.getElementById("msgDiv").appendChild(title);
var txt=top.document.createElement("p"); //显示提示内容的容器
txt.style.margin="1em 0"
txt.setAttribute("id","msgTxt"); //设置id
txt.innerHTML=str; //设置提示内容
top.document.getElementById("msgDiv").appendChild(txt); //添加提示内容
}
//-->
</SCRIPT>
<BODY>
<div height="100px">this is a test</div>
<input type="button" onclick="myAlert('haha,this is my designed alert dlg!')" id="btn"/>
</BODY>
</HTML>
[add]
非模态刷新父页面:window.opener.location.reload();
模态刷新父页面:window.dialogArguments.location.reload();
Response.Write("<script language=\"javascript\">\r\n");
Response.Write("<!--\r\n");
Response.Write("if(dialogArguments != null){\r\n");
// 注意上面的dialogArguments,就是父页面showModalDialog()的第二个参数。
// 就是父页面的window对象引用。
Response.Write("dialogArguments.location.reload(true);\r\n");
// 上面就是刷新父页的代码,相当于在父页上使用
// window.location.reload(true);代码
Response.Write("window.close();}"); // 关闭对话框
Response.Write("//-->\r\n</script>"); //关闭脚本块
}
上面的代码就是关闭对话框和刷新父页的代码,这段代码也可以直接写入editdata.aspx的html中,然后在后台cs中调用
[08-07-23-add]
void运算符号: void 运算符对任何值都返回undefined.该运算符通常用于避免输出不应该输出的值,例如从HTML的<a>元素调用javascrip函数时,要正确做到这一点,函数不能有返回值。
<a href="javascript:window.open('about:blank');" target =_blank>aa</a>
这个会出现2个窗口,一个窗口显示[object],一个显示空白页。
这个是因为 window.open 返回对新窗口的引用,然后该对象被转换成要显示的字符串。
要避免这个结果可以用 void运算符
这使window.open的返回值变成 undefined,他不是有效值,不会显示在游览器当中。
没有返回值的function 真正返回的都是undefined
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。




浙公网安备 33010602011771号