<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function msgClose(){
var msgw,msgh,bordercolor,titlecolor,tipClose;
msgw = 300;
msgh = 100;
bordercolor = "#005EBB";
titlecolor = "#005EBB";
tipClose = "<div style='width:20px; height:20px; font-size:18px; font-family:Arial;'>X</div>";var sWidth,sHeight;
sWidth = document.body.scrollWidth+20;
sHeight = document.body.scrollHeight+50;//整个DIV
var msgObj = 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.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+ "px";
msgObj.style.width = msgw + "px";
msgObj.style.height = msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight = "25px";
msgObj.style.zIndex = "10001";
//标题
var titleObj = document.createElement( "h4");
titleObj.setAttribute( "id", "msgTitle");
titleObj.setAttribute( "align", "left");
titleObj.style.margin = "0";
titleObj.style.padding = "4px";
titleObj.style.background = bordercolor;
titleObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20,startY=20,finishX=100,finishY=100,style=1,opacity=75,finishOpacity=100);";
titleObj.style.opacity = "0.75";
titleObj.style.border = "1px solid " + bordercolor;
titleObj.style.height = "20px";
titleObj.style.fontSize= "18px";
titleObj.style.color = "white";
titleObj.innerHTML = "操作失败";
//关闭窗口
var closeObj = document.createElement("div");
closeObj.style.margin = "0";
closeObj.style.padding = "0";
closeObj.style.width = "15px";
closeObj.style.height = "20px";
closeObj.style.color = "white";
closeObj.style.position= "absolute";
closeObj.innerHTML = tipClose;
closeObj.style.cursor = "pointer";
closeObj.style.left = "275px";
closeObj.style.top = "2px";
document.body.appendChild(msgObj);
document.getElementById("msgDiv").appendChild(titleObj);
document.getElementById("msgDiv").appendChild(closeObj);
closeObj.onclick = c;
//关闭背景和整个DIV
function c(){
document.body.removeChild(msgObj);
}
var txtObj = document.createElement("div");
txtObj.style.margin = "4px"
txtObj.setAttribute( "id", "msgTxt");
document.getElementById("msgDiv").appendChild(txtObj);
txtObj.innerHTML = "???<br /><a href='##' onclick='c();'>关闭</a>";
}
</script>
</head><body>
<a href="##" onclick="javascript:msgClose();">弹出</a>
</body>
</html>红色标记里面我应该怎么做可以让它关闭呢? 条件就是一定要赋值给innerHTML,也就是修改那句
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function msgClose(){
var msgw,msgh,bordercolor,titlecolor,tipClose;
msgw = 300;
msgh = 100;
bordercolor = "#005EBB";
titlecolor = "#005EBB";
tipClose = "<div style='width:20px; height:20px; font-size:18px; font-family:Arial;'>X</div>";var sWidth,sHeight;
sWidth = document.body.scrollWidth+20;
sHeight = document.body.scrollHeight+50;//整个DIV
var msgObj = 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.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+ "px";
msgObj.style.width = msgw + "px";
msgObj.style.height = msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight = "25px";
msgObj.style.zIndex = "10001";
//标题
var titleObj = document.createElement( "h4");
titleObj.setAttribute( "id", "msgTitle");
titleObj.setAttribute( "align", "left");
titleObj.style.margin = "0";
titleObj.style.padding = "4px";
titleObj.style.background = bordercolor;
titleObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20,startY=20,finishX=100,finishY=100,style=1,opacity=75,finishOpacity=100);";
titleObj.style.opacity = "0.75";
titleObj.style.border = "1px solid " + bordercolor;
titleObj.style.height = "20px";
titleObj.style.fontSize= "18px";
titleObj.style.color = "white";
titleObj.innerHTML = "操作失败";
//关闭窗口
var closeObj = document.createElement("div");
closeObj.style.margin = "0";
closeObj.style.padding = "0";
closeObj.style.width = "15px";
closeObj.style.height = "20px";
closeObj.style.color = "white";
closeObj.style.position= "absolute";
closeObj.innerHTML = tipClose;
closeObj.style.cursor = "pointer";
closeObj.style.left = "275px";
closeObj.style.top = "2px";
document.body.appendChild(msgObj);
document.getElementById("msgDiv").appendChild(titleObj);
document.getElementById("msgDiv").appendChild(closeObj);
closeObj.onclick = c;
//关闭背景和整个DIV
function c(){
document.body.removeChild(msgObj);
}
var txtObj = document.createElement("div");
txtObj.style.margin = "4px"
txtObj.setAttribute( "id", "msgTxt");
document.getElementById("msgDiv").appendChild(txtObj);
txtObj.innerHTML = "???<br /><a href='##' onclick='c();'>关闭</a>";
}
</script>
</head><body>
<a href="##" onclick="javascript:msgClose();">弹出</a>
</body>
</html>红色标记里面我应该怎么做可以让它关闭呢? 条件就是一定要赋值给innerHTML,也就是修改那句
倒数第一行的JS
txtObj.innerHTML = "???<br /><a href='##' onclick='c();'>关闭</a>";
还有一个^_^ http://topic.csdn.net/u/20080714/16/b927a471-acdb-4c01-8934-d5f20a22b368.html
function c(el){
document.body.removeChild(el);
return false;
}
var txtObj = document.createElement("div");
txtObj.style.margin = "4px"
txtObj.setAttribute( "id", "msgTxt");
document.getElementById("msgDiv").appendChild(txtObj);
txtObj.innerHTML = "<br /><a href='#' onclick='c(this);'>关闭</a>";
那你可以在创建<a>的时候也是使用creatElement啊
var txtObj = document.createElement("div");
txtObj.style.margin = "4px"
txtObj.setAttribute( "id", "msgTxt");
var hrefObj = document.createElement("a");
hrefObj.onclick = c;
hrefObj.href = "#";
hrefObj.innerHTML = "关闭";
txtObj.innerHTML = "???<br />";
txtObj.appendChild(hrefObj);
document.getElementById("msgDiv").appendChild(txtObj);
另外你这个有点问题吧
按道理来说应该是点击弹出的时候是显示一个已经存在的DIV
而不是重新创建
隐藏的时候也是设置属性使其隐藏而不是删除
隐藏和显示这个是可以 现在我做的是创建的DIV想在innerHTML里有关闭效果 呵呵