我的功能或按钮不起作用

时间:2015-09-05 00:48:24

标签: javascript function

感谢任何帮助,我的代码发布在下面。 我已经阅读了我的课程书,按照我教授的指示,在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;
}
}

1 个答案:

答案 0 :(得分:0)

我明白了。我今天在最后一行的变量前错过了一个+号。不管怎样,谢谢。