问题描述
想要的功能:我想在页面上点击一个按钮,然后弹出一个遮罩层,遮罩层显示时会绑定遮罩层内gridview的数据出来,然后点击遮罩层的关闭按钮关闭遮罩层。问题描述:使用js代码实现了遮罩层,使用一个<a>和html控件(inputtype=button)打开关闭遮罩层正常,但是如果我换成asp:button控件后查询数据库完成绑定,遮罩层层就不见了,请教这是怎么回事?<styletype="text/css">#fade{display:none;position:fixed;top:0%;left:0%;width:100%;height:100%;background-color:black;z-index:1001;-moz-opacity:0.8;opacity:.80;filter:alpha(opacity=80);}#light{display:none;position:absolute;top:10%;left:15%;width:70%;height:75%;padding:16px;border:3pxsolidorange;background-color:white;z-index:1002;overflow:auto;}</style><scripttype="text/javascript">window.onload=function(){varlinkbt=document.getElementById("btnpreview");varlight=document.getElementById('light');varfade=document.getElementById('fade');varclosebt=document.getElementById("closebt");linkbt.onclick=function(){light.style.display='block';fade.style.display='block';}closebt.onclick=function(){light.style.display='none';fade.style.display='none';}}</script><divid="light">里面有table和gridview等呈现数据的控件<br/><ahref="javascript:void(0)"id="closebt">关闭窗口</a></div><divid="fade"></div>
解决方案
解决方案二:
页面刷新了吗?
解决方案三:
asp.net的button控件,在js里需要<%=this.Button1.ClientID%>这样来获取id的。另外在你的onclick显示和隐藏都加上returntrue;再试试closebt.onclick=function(){light.style.display='none';fade.style.display='none';returntrue;}
解决方案四:
如果你不想触发后台的button事件。那么就returnfalse;