0 html javascript forms jquery
我有一个表格,其中的单元格接受键盘事件。我还有一个最初隐藏的表格。我想要一个键事件来显示表单并聚焦在输入字段上,但是当我这样做时,触发该事件的键值出现在输入字段中 - 我怎么能不显示这个字符呢?(例如,按“x”,表单的文本字段中将显示“x” - 我希望该字段为空)。
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;
}
Run Code Online (Sandbox Code Playgroud)
$(function() {
$('#tablediv').on('keydown', 'td', function(e) {
$('#formid').show();
$('#inputid').focus();
});
});
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)