簡體   English   中英

為什么我會收到SyntaxError:missing; 聲明前

[英]Why am I getting a SyntaxError: missing ; before statement

我收到了SyntaxError:缺少; 聲明前。 我不知道為什么會收到此錯誤,因為我的代碼與我正在使用的教科書完全相同。 請幫忙。 我將發布代碼,並注釋語法錯誤所在的位置:

<!DOCTYPE html>
<html lang="en">
<head>
<title> Practive</title>
<meta charset="utf-8">
<style>
input{display: block;
padding-bottom: 10px;
width: 250px;
text-align: left;}

label {float:left;}
</style>

<script type="text/javascript">
<!--
fuction validateForm()                           // SyntaxError: missing ; before statement
    //  before v
{
if (document.forms[0].userAge.value < 18){
alert ("Age is less than 18!");
return false;
} // end if 
alert ("Age is valid.");
return true;
} // end function validateForm
// -->
</script>
</head>

<body>
<h1> JavaScript Form Handling </h1>
<form method="post" action="http://webdevfoundations.net/scripts/formdemo.asp" onsubmit="return             validateForm();"> 
<label for="userName">Name: </label>
<input type="text" name="userName" id="userName">
<label for="userAge">Age:   &nbsp </label>
<input type="text" name="userAge" id="userAge">
<input type="submit" value="send information" id="submit">
</form>     

</body>

</html>

請注意:

fuction validateForm()  

應該:

function validateForm()  

您忘記了單詞功能中的N,而忘記了解決您的問題的方法。 :)

像這樣在腳本中編寫function而不是功能

function validateForm()                        
{
    if (document.forms[0].userAge.value < 18) {
        alert("Age is less than 18!");
        return false;
    } 
    alert("Age is valid.");
    return true;
} 

您在調用函數時犯了錯誤

更換

fuction validateForm()

function validateForm()

您在調用函數時犯了拼寫錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM