<html> <head> <title></title> <script type="text/javascript"> function sAlert(str) { var msgw, msgh, bordercolor; msgw = 300;//提示窗口的寬度 msgh = 200; //提示窗口的高度 titleheight = 25; //提示窗口標(biāo)題寬度 bordercolor = "#FF3C00"; //提示窗口的邊框顏色 titlecolor = "#D2CECE";//提示窗口的標(biāo)題顏色 var sWidth, sHeight; sWidth = document.body.clientWidth; //bod對象寬度 if (window.innerHeight && window.scrollMaxY) { sHeight = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight) { sHeight = document.body.scrollHeight; } else { sHeight = document.body.offsetHeight; } //以上得到整個屏幕的高 var bgObj = document.createElement("div"); //創(chuàng)建一個div對象 bgObj.setAttribute("id", "bgDiv"); bgObj.style.position = "absolute"; //絕對定位 bgObj.style.top = "0"; //頂部為0 bgObj.style.backgroud = "#777"; //背景顏色 bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishiOpacity=75)"; //ie瀏覽器透明度設(shè)置 bgObj.style.opacity = "0.6"; //透明度(火狐中) bgObj.style.left = "0"; //左邊為0 bgObj.style.width = sWidth + "px"; bgObj.style.height = sHeight + "px"; bgObj.style.zIndex = "100"; //層的z軸位置 document.body.appendChild(bgObj); var msgObj = document.createElement("div"); msgObj.setAttribute("id", "msgDiv"); msgObj.setAttribute("align","center"); msgObj.style.position = "absolute"; msgObj.style.top = "30%"; msgObj.style.backgroud = "white"; msgObj.style.border = "1px solid "+bordercolor; msgObj.style.left = "35%"; msgObj.style.font = "12px/1.6en Verdana,Geneva,Arial,Helvetica,sans-serif"; msgObj.style.width = msgw + "px"; msgObj.style.height = msgh + "px"; msgObj.style.textAlign = "center";//文本位置屬性,居中 msgObj.style.lineHeight = "25px"; //行間距 msgObj.style.zIndex = "101"; //層的z軸位置 var title = document.createElement("h4"); //創(chuàng)建一個h4對象 title.setAttribute("id", "msgTitle"); //為h4對象添加標(biāo)題 title.setAttribute("align", "right"); //文字的對齊方式 title.style.margin = "0"; //浮動 title.style.padding = "3px"; //浮動 title.style.backgroud = titlecolor; //背景顏色 title.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20,startY=20,finishX=100,finishY=100,style=1,opacity=75,finishiOpacity=100);"; title.style.opacity = "0.75"; //透明 //title.style.border = "1px solid" + bordercolor; title.style.height = "25px"; //高度 title.style.font = "12px Verdana,Geneva,Arial,Helvetica,sans-serif"; //字體屬性 title.style.color = "white"; //文字顏色 title.style.cursor = "pointer";//鼠標(biāo)樣式 title.innerHTML = "<a href=\"#\">關(guān)閉</a>";//顯示的文字 title.onclick = function () { document.body.removeChild(bgObj);//移除遮罩層 document.getElementById("msgDiv").removeChild(title); //在提示框中移除標(biāo)題 document.body.removeChild(msgObj);//移除提示框 } document.body.appendChild(msgObj); //在body中畫出提示框?qū)? document.getElementById("msgDiv").appendChild(title); //在提示框中增加標(biāo)題 var txt = document.createElement("p"); txt.style.margin = "0";//文本浮動 txt.setAttribute("id", "msgTxt");//為p屬性增加id屬性 txt.innerHTML = str;//把傳進來的值賦給p屬性 document.getElementById("msgDiv").appendChild(txt); //把p屬性增加到提示框中 } </script> </head> <body> <a href="#" onclick="sAlert('<a href=http://www.>測試效果</a>');">點擊測試</a> </body> </html>
|