* 显示一个弹出界面
*
* @param url
*界面地址,可以使jsp,页也可以是action
* @param params
*需要传递的参数
* @param titleDesc
*页面头描述
* @param width
*页面宽度
* @param height
*页面高度
* @param parentView
*页面所在的父页面
* @param callback
*回调函数
*/
function showPage(url, params, titleDesc, width, height, parentView, callback) {
var _win = this
if (!parentView) {
parentView = document
}
lockScreen_showPage(parentView)
var bordercolor = "#336699"// 提示窗口的边框颜色
var showPageDiv = parentView.createElement("div")
showPageDiv.setAttribute("id", "showPageDiv")
showPageDiv.setAttribute("align", "center")
showPageDiv.style.background = "white"
// showPageDiv.style.border = "1px solid " + bordercolor
showPageDiv.style.position = "absolute"
showPageDiv.style.left = "50%"
showPageDiv.style.top = "30%"
showPageDiv.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"
showPageDiv.style.marginLeft = "-225px"
showPageDiv.style.marginTop = -75 + parentView.documentElement.scrollTop + "px"
showPageDiv.style.width = width + "px"
showPageDiv.style.height = height + "px"
showPageDiv.style.textAlign = "center"
showPageDiv.style.lineHeight = "25px"
showPageDiv.style.zIndex = "10031"
var title = parentView.createElement("h4")
title.setAttribute("id", "showPageTitle")
title.setAttribute("align", "right")
title.style.margin = "0"
title.style.padding = "3px"
// title.style.background = bordercolor
title.style.filter = "progid:DXImageTransform.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 Verdana, Geneva, Arial, Helvetica, sans-serif"
// title.style.color = "white"
title.style.cursor = "pointer"
title.title = titleDesc
title.innerHTML = "<table border='0' width='100%'><tr><td width='85%' align='left'><b id='showPageTitleDesc'>"
+ titleDesc + "</b></td><td id='showPageClose' width='15%' >关闭</td></tr></table>"
var pageBody = parentView.createElement("div")
pageBody.setAttribute("id", "pageBody")
pageBody.style.width = width + "px"
if (navigator.userAgent.indexOf("MSIE 6.0") >0) {// IE6
pageBody.style.height = height - 26 + "px"
} else {// IE8
pageBody.style.height = height - 25 + "px"
}
pageBody.style.position = "absolute"
pageBody.style.left = "0px"
$.post(url, params, function(data) {
showPageDiv.appendChild(title)
showPageDiv.appendChild(pageBody)
parentView.body.appendChild(showPageDiv)
parentView.getElementById("showPageClose").onclick = function() {
closeShowPage(parentView)
if (callback) {
callback.call(_win)
}
}
$("#pageBody").html(data)
})
}
试试调用这个方法
随机产生一个数(1-n) n为网页数
var num=Math.floor(Math.random()*n+1)
每个数对应一个网页地址
var src
switch(num)
{
case 1:
src=第一个网页地址
break
case 2:
src=第一个网页地址
break
.
.
.
case n:
src=第n个网页地址
break
default:
src=""
}
3. window.open(src)
通过JS代码 document.getElementById('divID').style.etElementById('divID').style.display = 'none'。函数可以实现。
1、遮罩层:<div id="back"></div>,即作为背景层,覆盖整个页面。弹出层:<div id="form"></div>,即背景层上的一层,此层可根据#form{top: 10%left: 10%width: 20%height: 30%},调整弹出层的弹出位置。
2、弹出层和遮罩层全部为div标签,可以利用display来控制显示和隐藏的属性,在js中,显示: document.getElementById('divID').style.display = document.getElementById('divID').style.display = 'none'。
3、显示遮罩层和弹出层,即可用图中popDiv()函数表示: 其中,showId 表示弹出层的divId, backId 表示遮罩层的divId;函数第去、2行显示弹出层和遮罩,3、4、5行设置遮罩层的长度、宽度。
4、关闭弹出层和遮罩层用hideDiv函数(), 其中:showId 表示弹出层的divId, backId 表示遮罩层的divId;先关闭弹出层,后关闭遮罩层。
5、点击按钮后,弹出,要给按钮加上onclick函数,<button onclick="popDiv('form','back')">点我,显示弹出层</button>。
6、整体代码如下,css 样式可根据个人的喜好自行添加。