【发布时间】:2015-07-09 12:44:33
【问题描述】:
我有一个表格,其中单元格接受键盘事件。我也有一个最初隐藏的表格。我想要一个键事件来显示表单并关注输入字段,但是当我这样做时,触发事件的键值出现在输入字段中 - 我怎么能不显示这个字符? (例如,按“x”,表单会在文本字段中显示“x” - 我希望该字段为空白)。
CSS
table.thistbl td {
border: 2px solid black;
width: 20px;
height: 20px;
padding: 5px;
}
#formid {
display: none;
position: absolute;
width: 300px;
height: 40px;
left: 20px;
top: 60px;
background-color: #CCC;
}
JavaScript / jQuery:
$(function() {
$('#tablediv').on('keydown', 'td', function(e) {
$('#formid').show();
$('#inputid').focus();
});
});
HTML:
<div id="tablediv">
<table class="thistbl">
<tr>
<td tabindex="0"></td>
<td tabindex="0"></td>
<td tabindex="0"></td>
</tr>
</table>
</div>
<form id="formid">
<input type="text" tabindex="1" id="inputid" />
</form>
【问题讨论】:
-
只是一个想法...:您可以尝试使用 keyup-event 来代替吗?
标签: javascript jquery html forms