JS弹出DIV窗口,按ESC取消

如题所述

  显示层:

css:
.showdiv
{
width: 100%;
height: auto;
position: absolute;
left: 0;
top: 0;
z-index: 999;
display: none;
}
.count_div
{
width: 500px;
height: 400px;
margin-top: 120px;
margin-left: auto;
margin-right: auto;
margin-bottom: 0;
border: 1px solid #aaaaaa;
background: #fff;
}
.brg
{
width: 100%;
background: #ededed;
position: absolute;
top: 0;
left: 0;
filter: alpha(opacity=60);
-moz-opacity: 0.6;
opacity: 0.6;
position: absolute;
top: 0;
left: 0;
display: none;
z-index: 998;
}

js:
function close () {
$("#brg").css("display", "none");
$("#showdiv").css("display", "none");
}
function show() {
$("#brg").css("display", "none");
$("#div_show").css("display", "none");
}
 $(document).bind('keydown', 'esc',function (evt){
  //关闭层代码
close () ;
  return false; });

  html:
  <!--遮罩层-->
  <div class="brg" id="brg">
  </div>
  <!--显示层-->
  <div class="showdiv" id="div_order">
  <div class="count_div" id="div_order_count">
  内容
  </div>
  </div>
  在网上找一个“jquery.hotkeys.js”的js包,里面都是jquery整理好的热键,
  引入jquery包。
  $(document).bind('keydown', 'esc',function (evt){
  //关闭层代码
  return false; });
手敲,未测试,应该不会有太大问题,根据自己内容修改
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-01-10
是的 ,把ESC 用js写进去做关闭div 就可以的了呀.
第2个回答  2013-01-10
自己找一下ESC键的JS代码是什么来表示的。然后你就可以通过JS来完成关闭功能了。
第3个回答  2013-01-10
用 artdialog这个jquery 插件吧。很好用。
相似回答