使用jQuery关闭ESC按键时的自定义框 [英] Close a customized box at ESC keypress with JQuery
本文介绍了使用jQuery关闭ESC按键时的自定义框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的对话框具有以下HTML代码:
I have the following HTML code for dialog box:
<div id="modal-dialog" class="no-display">
<div class="form">
<div class="close">
</div>
<div align="center">
<h2><u>form</u></h2>
</div>
<form>
<label for="yourname">Full name:</label><input type="text" name="yourname">
<label for="email">E-mail:</label><input type="text" name="email">
<label for="message">Message:</label></textarea><textarea type="text" name="message"></textarea><br/>
<div class="clear"></div>
<p align="center"><button>Send feedback</button></p>
</form>
</div>
</div>
javascript:
The javascript :
$("#clickfeed").live("click", function() {
$("#modal-dialog").removeClass("no-display");
});
我写道:
$("#modal-dialog").live("keyup", function(e) {
if(e.keyCode === 27 && !($(this).hasClass("no-display")))
{
$("#feedback-modal-dialog input").each(function() {
$(this).attr("value","");
});
$("#feedback-modal-dialog textarea").each(function() {
$(this).val("");
});
$("#modal-dialog").addClass("no-display"); //or .hide()
}
});
ESC
键仅在输入聚焦时起作用,否则不起作用.
The ESC
key works only if an input is focused otherwise not.
我想在按ESC
时关闭modal-dialog
框.
我的JS代码有误吗?
谢谢
推荐答案
这是怎么回事:
$("html").live("keyup", function(e) {
if(e.keyCode === 27 && !($('#modal-dialog').hasClass("no-display")))
escape_check();
}
}
function escape_check() {
$("#modal-dialog").removeClass("no-display");
$("#feedback-modal-dialog input").each(function() {
$('#modal-dialog').attr("value","");
});
$("#feedback-modal-dialog textarea").each(function() {
$('#modal-dialog').val("");
});
$("#modal-dialog").addClass("no-display"); //or .hide()
}
这篇关于使用jQuery关闭ESC按键时的自定义框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文