我的功能或按钮不起作用

My function or button isn't working

本文关键字:不起作用 按钮 功能 我的      更新时间:2023-09-26

感谢任何帮助,我的代码张贴在下面。我读了我的课本,按照我的教授的指示,上了youtube,读了论坛,但仍然不知道为什么我的按钮在我点击它时没有运行我的功能。请帮助。

HTML:

<!doctype html>
<head>
<h1>Exercise 3-1</h1>
<script src ="X_3_1.js"></script>
</head>
<body>
<p>Enter First Name:
<input type="text" id="firstName">
<br>
 Do you have children?:
 <input type="text" id="children">
 <br>
  If so, how old is your oldest child?:
 <input type="text" id="oldestChild">
 <br>
 <input type="button" onclick="processInfo()" value="Submit Information">
 <br>
 <span id="mymsg">*</span>
 </p>
 </body>
 </html>

JS:

function processInfo()
{
var firstName = document.getElementById("firstName").value;
var children = document.getElementById("children").value;
var oldestChild = document.getElementById("oldestChild").value;
var childrenLower = children.toLowerCase();
var today = new Date ();
if(childrenLower == "yes" || childrenLower == "y")
{
if(isNaN(oldestChild)){
    mymsg.firstChild.nodeValue = oldestChild + " is not a number";
} else if(oldestChild <= 19){
    mymsg.firstChild.nodeValue = "You still have kids at home";
} else if(oldestChild >= 19){
    mymsg.firstChild.nodeValue = "Hopefully they have moved out of the
house";
} 
} else if(childrenLower != "yes" || childrenLower != "y") {
mymsg.firstChild.nodeValue = "It must be peacefule at home, " +
firstName + "on this date of " today;
}
}

我明白了。我在最后一行的变量前少了一个加号。谢谢。