现在有一个DIV 的遮罩层,这个层上面还放了一个DIV里面有一个输入框
现在var vname = window.document.getElementById("txtName").value; alert(vname);这种方式得不到vname 的值,很郁闷为什么
现在var vname = window.document.getElementById("txtName").value; alert(vname);这种方式得不到vname 的值,很郁闷为什么
<form id="Form1" runat="server">
<h2 class="cj-login">
<a class="register-link" href="#" onclick="UserAddressWrite();"></a>
</h2>
<!--弹出的层-->
<div id="addressUserDiv" style="display:none ">
<div class="intro-box">
<div class="content">
<b class="close"><a href="#" onclick="new Msg().MoniWin.Close();">
<img src="../images/201105/close.gif" width="14" height="14" /></a></b>
<p class="text">
请填写姓名
<br />
姓名:<input id="txtName" name="txtName" type="text" class="text-input" maxlength="20" /><br />
</p>
<div class="btn">
<br />
<input name="" type="button" class="sure" onclick="saveUserInfo();" />
<script type="text/javascript">
function saveUserInfo() {
debugger;
var vname = window.document.getElementById("txtName").value;
var vaddress = window.document.getElementById("txtAddress").value;
var vpost = window.document.getElementById("txtPost").value;
var vphone = window.document.getElementById("txtPhone").value;
alert(vname);
}
</script>
</div>
</div>
</div>
</div>
</form>
</body>
<script type="text/javascript"> function UserAddressWrite() {
debugger;
var msg = new Msg();
msg.MoniWin.Width = "100px";
msg.MoniWin.Move = true; //允许拖动
msg.MoniWin.MoveID = "addressUserDiv"; //拖动执行的ID对象
msg.MoniWin.Open(window.document.getElementById("addressUserDiv").innerHTML);
msg.MoniWin.MaskHWbyBody = function () {
var _t = document.body.scrollTop && document.body.scrollTop > 0 ? document.body.scrollTop : document.documentElement.scrollTop;
msg.MoniWin.Win.style.top = (500 + _t) + "px";
}
msg.MoniWin.MaskHWbyBody();
// setString("UserAddressWrite()");
}</script>
</html>
if(txtNameElem)
{
alert(txtNameElem.value);
}
else
{
alert('cannot find the element');
}
注释那三行 ,看嫩弹出么 。
<!--弹出的层-->
<div id="addressUserDiv" style="display:none ">中的 style="display:none " 去掉就可以得到值了
可以弹出,但是就是取不到姓名里面的值,是空的,如果style="display:none " 不要这个就可以值到值了
this.company = "";
this.href = "";
this.team = "";
this.Win = null;
this.Mask = null;
this.width="";
}
var mp = Msg.prototype;
/****************模拟窗体 开始******************
直接打开独立页面:mp.MoniWin.ToUrl('inner.htm');
输出指定字符内容:mp.MoniWin.Open('指定字符内容');*/
mp.MoniWin = {
Width:"400px",
Height:"335px",
Move:false,
MoveID:"",
Close: function() { //关闭模拟窗体及遮罩
this.Mask.style.display = "none";
this.Win.style.display = "none";
JSHelper.SelectVisibility("visible");
},
Open: function(fctContent) { //打开一个模拟窗体及遮罩,fctContent为显示内容、可以调用该方法之后通过 mp.MoniWin.Win.innerHTML来改变内容 fctContent = (fctContent ? fctContent : "没有内容");
var varBodyTLWH = JSHelper.getBodyTLWH();
if (JSHelper.$("divPyzyMask")) {
this.Win = JSHelper.$("divMoniWin");
this.Win.innerHTML = fctContent;
this.Win.style.display = "block";
this.Mask = JSHelper.$("divPyzyMask");
this.Mask.style.display = "block";
} else {
//Body内容加载变化或窗体大小改变则遮罩自动适应
if (window.attachEvent) { //兼容IE
window.attachEvent("onload", function() { mp.MoniWin.MaskHWbyBody(); });
window.attachEvent("onresize", function() { mp.MoniWin.MaskHWbyBody(); });
window.attachEvent("onscroll",function(){mp.MoniWin.MaskHWbyBody();})
} else { //兼容火狐
window.addEventListener("load", function() { mp.MoniWin.MaskHWbyBody(); }, false);
window.addEventListener("resize", function() { mp.MoniWin.MaskHWbyBody(); }, false);
window.addEventListener("scroll", function() { mp.MoniWin.MaskHWbyBody(); }, false);
}
this.Mask = JSHelper.createElement("div", "divPyzyMask", "position:absolute;z-index:100;left:0px;top:0px;width:100%;height:800px;background-color:#000000;filter:Alpha(Opacity=60);opacity:0.6;", document.body); this.Win = JSHelper.createElement("div", "divMoniWin", "position:absolute;z-index:999;left:50%;top:50%;margin:-167px auto auto -220px;", document.body);
//this.Win.style.width="";
this.Win.style.width=this.Width;
this.Win.style.height=this.Height;
this.Win.style.top=250+document.body.scrollTop+"px";
this.Win.innerHTML = fctContent;
}
if(this.Move && this.MoveID!=""){
var h= document.getElementById(this.MoveID);
h.style.cursor="move";
if (window.attachEvent) {
h.attachEvent("onmousedown",mp.MoniWin.MoveWin);
}else
{
h.addEventListener("mousedown",mp.MoniWin.MoveWin, false);
}
}
this.Mask.style.height = varBodyTLWH.height + "px";
this.Mask.style.width = varBodyTLWH.width + "px";
JSHelper.SelectVisibility("hidden");
mp.MoniWin.MaskHWbyBody();
},
MoveWin:function(t){
var s=document.getElementById("divMoniWin").style;
var varBodyTLWH = JSHelper.getBodyTLWH();
// var e = t.srcElement;
// if (!e) {
// e = t.currentTarget;
// }
var e=t;
var x = e.clientX + varBodyTLWH.left - s.pixelLeft;
var y = e.clientY + varBodyTLWH.top - s.pixelTop;
var m = function(){
if(e.button == 1){
s.pixelLeft = e.clientX + varBodyTLWH.left - x;
s.pixelTop = e.clientY + varBodyTLWH.top - y;
}else {
document.detachEvent("onmousemove", m);
}
}
if (window.attachEvent) {
document.attachEvent("onmousemove", m)
}else{
document.addEventListener("mousemove",m,false);
}
e.cancelBubble = true;
},
MaskHWbyBody: function() { //调整遮罩适应BODY的宽高
var varBodyTLWH = JSHelper.getBodyTLWH();
this.Mask.style.height = varBodyTLWH.height + "px";
this.Mask.style.width = varBodyTLWH.width + "px";
this.Win.style.top=150+document.body.scrollTop+"px";
},
iframeLoad: function(fctTheObj, fctWidth, fctHeight) { //引用外部页加载完毕事件 若不指定fctWidth则自动适应iframe宽高
mp.$("divLoadWindowStatus").style.display = "none";
if (fctWidth == null) {
var iframeDocument = (fctTheObj.Document ? fctTheObj.Document : fctTheObj.contentDocument);
fctWidth = iframeDocument.body.scrollWidth;
fctHeight = iframeDocument.body.scrollHeight;
}
fctTheObj.style.height = fctTheObj.offsetParent.style.height = fctHeight + "px";
fctTheObj.style.width = fctTheObj.offsetParent.style.width = fctWidth + "px";
fctTheObj.offsetParent.style.margin = "-" + (fctHeight / 2) + "px auto auto -" + (fctWidth / 2) + "px";
},
//内容引用外部页 参数分别为地址、隐藏关闭按钮、指定iframe宽度、指定iframe高度(若不指定宽高则启动程序自动适应,跨域时将出现权限错误)
ToUrl: function(fctUrl, fctHidClose, fctWidth, fctHeight) {
this.Open('\
<div id="divLoadWindowStatus" style="color:red;text-align:center;padding:10px;font-weight:bold;background-color:#F0F0F0;line-height:31px;height:31px;">\
<span style="font-weight:100;float:right;cursor:pointer;color:#666;" onclick="mp.MoniWin.Close();return false;">[取消]</span>\
数据获取中,请稍候...\
</div>\
<iframe id="iframePyzyWin" scrolling="no" src="' + fctUrl + '" frameborder="0" onload="mp.MoniWin.iframeLoad(this' + (fctWidth == null ? '' : ',' + fctWidth + ',' + fctHeight) + ');"></iframe>\
');
}
};这是其中的一个JS 文件 可能是这里面有问题
<div id="addressUserDiv" >function initAddressUserDiv()
{
document.getElementById("addressUserDiv").style.display = "none";
}