简体   繁体   English

单击“更改页面布局”按钮时不执行任何操作

[英]The "change page layout" button doesn't do anything when clicked

So, I should preface this by saying that I'm not an expert coder.所以,我应该先声明我不是专家编码员。 In fact, I'm taking a computer science class and currently I only know HTML, CSS, and some Javascript. This has stumped me.事实上,我正在学习计算机科学 class,目前我只知道 HTML、CSS 和一些 Javascript。这让我很困惑。

So, when I push that button at the bottom with the ID "btn1", it's supposed to trigger the changeLayout function. I plan to add more to the function later, but right now I've added a piece of code to write "hi" in the text box with the ID "firstname" to test if it works.所以,当我按下 ID 为“btn1”的底部按钮时,它应该会触发 changeLayout function。我计划稍后向 function 添加更多内容,但现在我已经添加了一段代码来编写“hi " 在 ID 为“firstname”的文本框中测试它是否有效。 Except, when I push the button, nothing happens.除了,当我按下按钮时,没有任何反应。 So far I've tried changing the button from an input type of button to just a button tag, I've tried changing the ID and function names multiple times, I've tried changing the.value to a.innerHTML in the function, and nothing has worked so far.到目前为止,我已经尝试将按钮从输入类型的按钮更改为按钮标签,我已经尝试多次更改 ID 和 function 名称,我已经尝试将 function 中的.value 更改为 a.innerHTML,到目前为止没有任何效果。

<!DOCTYPE html>
<html>
<head>
<script>
    function mouseOver () {
        window.alert('Click here to accept cookies!')
    }
    function bannedKey () {
        window.alert('Sorry, that is a banned key. Please try again.')
    }
    function changeLayout(form) {
        document.getElementbyId("firstname").value = "hi"
    }
</script>
</head>
<body>
    <form>
        <fieldset>
        <b>First Name: </b><input type="text" name="keyjoke" onkeypress="bannedKey()" id="firstname" value=""><br>
        <b>Last Name: </b><input type="text" name="keyjoke" onkeypress="bannedKey()"><br>
        <button onmouseover="mouseOver()">Submit!</button>
        </fieldset><br>
        <input type="button" id="btn1" onclick="changeLayout(this.form)" value="Click here to change the page layout!">
    </form>
</body>
</html>

It's not "getElementbyId".这不是“getElementbyId”。 It's "getElementById" (capital B in "By").它是“getElementById”(“By”中的大写 B)。

document.getElementById("firstname").value = "hi" document.getElementById("firstname").value = "hi"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM