你能告诉我为什么这行不通吗?一整天都在坚持。
我只想复制第一个字段中输入的任何内容,将其转换为变量并将其投影到最后一个
字段。
谢谢
ps: 不用说我只复制了代码的相关位...
<th bgcolor="#eeeee" width=12.5%>Monday</th>
<th bgcolor="#eeeee" width=12.5%><input id="test" value="09:15" size=15></td></th>
<th bgcolor="#eeeee" width=12.5%><input type=time id="Monday_Breakfast_LastSeating" value="11:45" size=15></td></th>
</form>
</table>
<form id="form2" id=other method=POST>
<tr>
<td bgcolor="#aaeeaa"align=center><button onclick="myFunction()">Calculate</button></td>
</tr>
</form>
<table width=40% border=0>
<th bgcolor="#eeaaaa" align=center width=33%>Goal</th>
</table>
<form id=result method=POST>
<table width=40% border=0>
<th style="border:black;" bgcolor="#eeaaaa" align=center><em></em> <p id="calculation2" size=15>N/A</p></th>
<th bgcolor="#eeaaaa" align=center><em></em> <p id="calculation3" size=15>N/A</p></th>
<th bgcolor="#eeaaaa" align=center><p id="calc" size=15>N/A</p></th>
</table>
</form>
<script type="text/javascript">
function myFunction() {
var test = getElementById("test").value;
document.getElementById("calc").innerHTML = test;
}
</script>
最佳答案
您忘记了第一个 getElementById
之前的 document.
function myFunction() {
var test = document.getElementById("test").value; // you forgot the document. here..
document.getElementById("calc").innerHTML = test;
}
此外,p
元素没有size
属性。 (也许您想使用 input
元素。但是对于那些您应该使用 value
属性而不是 innerHTML
来设置它们..)
关于javascript - 用于 JavaScript 的 getElementById jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11415552/