问题
Example: when I press key "A" on a keyboard, then the value will change to "S" and text box show up "S".
How can I do this with jQuery or Tinymce 4?
Thank you very much!
回答1:
You will need to check the keyCode
in every keypress
event. If the keyCode
is the same with A
then you need to change it to whatever string you want, for example: S
.
<div>
<label>Test:</label>
<input type="text" id="test">
</div>
$("#test").on("keypress", function (e) {
if (97 == e.keyCode || 65 == e.keyCode) {
e.preventDefault();
var newString = $("#test").val() + "S";
$("#test").val(newString);
}
});
97
is the keycode for a
and 65
is keycode for A
.
a
will not be shown in the box with e.preventDefault();
Fiddle is here.
来源:https://stackoverflow.com/questions/38236831/jquery-change-keyboard-value-when-input