我不能为我的生活找出为什么以下不起作用。我从W3school的例子here拿走了。获取输入值并在另一个div中显示
基本上我想从输入文本中取值,当它更改并修改另一个div以包含该值时。我只想让div显示新的价值,但我确实希望每次都改变它,所以我认为onchange是要走的路。
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
var div = document.getElementById('divID');
div.innerHTML = div.innerHTML + x.value;
}
</script>
</head>
<body>
Enter your name: <input type="text" id="fname" onchange="myFunction()">
<p>When you leave the input field, a function is triggered which transforms the input text to upper case.</p>
<div id="divID"></div>
</body>
</html>
在此先感谢所有的帮助。
什么是'x.value'? – 2013-12-24 02:39:54
“当您离开输入栏时,会触发一个功能,将输入文本转换为大写。”功能在哪里? – 2013-12-24 02:47:04
对不起,我忘了定义了x.value的那段代码。 Chancho的假设对这笔钱是正确的。 – MattSizzle