我使用Ajax显示了一个弹出面板窗口,现在我想要在用户按下Esc键时关闭该窗口。
这个可行吗?如果有人知道或之前做过,请帮助我。
谢谢
我使用Ajax显示了一个弹出面板窗口,现在我想要在用户按下Esc键时关闭该窗口。
这个可行吗?如果有人知道或之前做过,请帮助我。
谢谢
这是一个链接,你可以通过点击“esc”键来轻松关闭窗口:
http://www.codeproject.com/KB/scripting/Javascript_for_modalpopup.aspx
希望这能有所帮助。
<script type="text/javascript">
function pageLoad(sender, args){
if(!args.get_isPartialLoad()){
// add our handler to the document's
// keydown event
$addHandler(document, "keydown", onKeyDown);
}
}
function onKeyDown(e){
if(e && e.keyCode == Sys.UI.Key.esc){
// if the key pressed is the escape key, dismiss the dialog
$find('mdlPopupExtender').hide();
}
}
</script>
<script type="text/javascript">
document.onkeyup =Esc;
function Esc()
{
var KeyID =event.keyCode;
if(KeyID==27)
{
if($find("p2"))
{
$find("p2").hide();
}
if($find("p3"))
$find("p3").hide();
}
}
</script>