javascript - 用于 JavaScript 的 getElementById jquery

标签 javascript

你能告诉我为什么这行不通吗?一整天都在坚持。

我只想复制第一个字段中输入的任何内容,将其转换为变量并将其投影到最后一个

字段。

谢谢

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/

相关文章:

javascript - 使用 css 显示子菜单

javascript - 使用逗号值作为饼图中的数据点

javascript - 如何从表格(由 div 组成)中制作标题是静态的还是固定的

Javascript 正则表达式不匹配 - 包含完整代码

c# - 在 Asp.net 上检测浏览器关闭

javascript - 来自终端的 npm install 错误

javascript - AJAX 删除不工作的 Entity Framework

带 URL 的 Javascript 模态弹出窗口

javascript - 在 VS Code 中突出显示 "Cannot find name"/"any"

javascript - Json服务器错误: Data must be an object.需要将JSON数组更改为JSON对象