[英]Saving user input directly into variable in JQuery
I don't want to have a formal form field but save every user input directly into a variable and append new letters to a field every time the user enters a new letter. 我不想有一个正式的表单字段,但是将每个用户输入直接保存到变量中,并在用户每次输入新字母时将新字母追加到字段中。 What command do I need?
我需要什么命令?
window.onkeypress = function(e) {
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
document.body.innerHTML += character;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.