Yes: you need to add a tabindex
attribute to the <div>
to allow it to receive the focus.
<div id="idtext" tabindex="1"></div>
Also, the property you want for the character code of the text entered in a keypress event is which
, not keyCode
.
Finally, the HTML comment tags inside the <script>
element are unnecessary in all modern browsers.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…