我正在尝试创建某种桌面键盘(在我的文本字段中使用/写入基里尔字母)。我遇到了由于变量的赋值而只能写第一个字母的问题。
有人可以告诉我一个简单的方法来解决这个问题吗?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script language="javascript" type="text/javascript">
function rukeyboard() {
var newtext = document.Keyboard.A.value; // <-- Problem is that newtext is only pointed to Keyboard.A but should be usable for 33 letters
document.Keyboard.outputtext.value += newtext;
}
</script>
</head>
<body>
<form name="Keyboard">
<input type="button" name="A" value="A" onClick="rukeyboard();">
<input type="button" name="B" value="B" onClick="rukeyboard();">
<input name="outputtext">
</form>
</body>
</html>
最佳答案
这应该可以解决您的目的:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script language="javascript" type="text/javascript">
function rukeyboard(button) {
var newtext = button.value; // <-- Problem is that newtext is only pointed to Keyboard.A but should be usable for 33 letters
document.Keyboard.outputtext.value += newtext;
}
</script>
</head>
<body>
<form name="Keyboard">
<input type="button" name="A" value="A" onClick="rukeyboard(this);"> <input type="button" name="B" value="B" onClick="rukeyboard(this);">
<input name="outputtext">
</form>
</body>
</html>
这是一个 fiddle :https://jsfiddle.net/wet32n06/
关于javascript - 使用按钮将文本写入输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36010826/