Javascript 函数未被调用或未运行

Javascript 函数未被调用或未运行,javascript,function,Javascript,Function,我已经在这方面工作了一周了,我一辈子都不知道我错过了什么,也不知道我是否把什么东西放在了不该放的地方。在我开始对confirmSubmit函数进行更改之前,代码一直运行良好,现在除了显示页面外,似乎没有任何东西正常工作。我让我的老师也看了,他说他也看不出来。我只是不知道也许你们中的一个能帮我解决这个问题 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dt

我已经在这方面工作了一周了,我一辈子都不知道我错过了什么,也不知道我是否把什么东西放在了不该放的地方。在我开始对confirmSubmit函数进行更改之前,代码一直运行良好,现在除了显示页面外,似乎没有任何东西正常工作。我让我的老师也看了,他说他也看不出来。我只是不知道也许你们中的一个能帮我解决这个问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="AS400.css" type="text/css" />
<title>Registration</title>

<script type="text/javascript">
    /* <![CDATA[ */
    // This JavaScript removes default values form field
       function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }

// This JavaScript allows characters except numbers
 function AcceptLetters(objtextbox)
{
var exp = /[^\D]/g;
objtextbox.value = objtextbox.value.replace(exp,'');
}

// This JavaScript allows numbers only
 function AcceptDigits(objtextbox)
{
var exp = /[^\d]/g;
objtextbox.value = objtextbox.value.replace(exp,'');
}

//This JavaScript confirms everything is filled out
function confirmSubmit()
{
var submitForm = window.confirm("Are you sure you want to submit the form?");
var Special offers = false;
var offers = false;



if (document.forms[0].name.value=="Name" || document.forms[0].name.value == "") {
     window.alert("Please input your name.");
    return false;}

 if (document.forms[0].email.value == "E-Mail Address" || document.forms[0].email.value == "") {
    window.alert("Please input your email.");
    return false;}

    if (document.forms[0].password1.value == "" || document.forms[0].password2.value == "") {
    window.alert("Please input your password twice.");
    retrun false;}

if (document.forms[0].SQ.value == "" || document.forms[0].SQ.value == "none") {
    window.alert("Please choose a security question.");
    return false;}

if (document.forms[0].sq_answer.value == "Question Answer"|| document.forms[0].sq_answer.value == "") {
    window.alert("Please input a sequrity question answer.");
    return false;}

    for (var i = 0; i <= 1; ++i) {

    if (document.forms[0].SpecialOffers[i].checked ==  true) {
        Special offers = true;
        break;}
    }

    if (Special offers == false) {
        window.alert("You must select yes or no to special offers.");
        return false;
    }


    for (var k = 0; k <= 3; k++) {
    if (document.forms[0].Offers[k].checked == true) {
        offers = true;
        break;}

    }
    if (offers == false) {
        window.alert("You must choose one offer.");
        return false;}

else
 return true;
 }

/* ]] */
</script>
</head>

<body>


<form  action="FormProcessor.html"  method = "get" enctype = "application/x-www-form-urlencoded" onsubmit="return confirmSubmit()">
<table  width="50%">
<tr><th colspan="2"><h1>Registration Page</h1></th></tr>

<tr><th colspan="2"><h2>Personal Information<h2></th></tr>
<tr><th colspan="2">(Fields with asterisks are mandatory)</th></tr>
<tr><td>* Name: </td>
<td><input type="text" name="name" value="Name" maxlength="20"  onFocus="doClear(this)" onkeyup="AcceptLetters(this)" /></td></tr>
<tr><td>* E-Mail:</td>
<td><input type="text" name="email" value="E-mail Address" onFocus="doClear(this)" /> </td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><th colspan="2"><h3>Security Information</h3></th></tr>
<tr><td>* Password:</td><td><input type="password" name="password1" /></td></tr>
<tr><td>* Confirm Password:</td><td><input type="password" name="password2" /></td></tr>
<tr><td>* Security Question:</td>
<td><select id="selection" name="SQ">
<option value="none">Please Choose One</option>
<option value="color">What is your favorite color?</option>
<option value="name">What is your Mother's maiden name?</option>
<option value="pet">What is your pets name?</option>
<option value="school">What high school did you graduate from?</option>
</select></td></tr>
<tr><td>Answer:</td><td><input type="text" name="sq_answer"  value="Question Answer" onFocus="doClear(this)" /></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><th colspan="2"><h4>* Preferences</h4></th></tr>

<tr><th colspan="2">Would you like any special offers sent to your E-mail address?</th></tr>
<tr><th colspan="2">Yes<input type="radio" name="SpecialOffers" value="Yes"/>No<input type="radio" name="SpecialOffers"  value="No" /></th></tr>
<tr><th colspan="2"><h5>Interests</h5></th></tr>
<tr><th colspan="2"><input type="checkbox" name="Offers" value="check"/>Entertainment</th></tr>
<tr><th colspan="2"><input type="checkbox" name="Offers" value="check"/>Shopping</th></tr>
<tr><th colspan="2"><input type="checkbox" name="Offers" value="check"/>Business</th></tr>
<tr><th colspan="2"><input type="checkbox" name="Offers" value="check"/>Exercise</th></tr>
<tr><td></td></tr>


<tr><th colspan="2"><input id="submit" type="submit" value="Submit"/><input id="reset" type="reset" value="Reset"/></th></tr>
</table>

</form>

</body>
</html>

您几乎没有语法错误:

特殊优惠变量中不能有空格


关键字未返回。是否尝试过使用Firebug或Chrome开发工具调试代码?如果您的页面未显示内容或工作不正常,则脚本中可能存在错误,调试它会发现问题的根源。我在Chrome中尝试使用你的页面时遇到很多控制台错误。它正在正确显示内容。但它并没有使用函数,这不是我们在这里要做的。我们不会在没有任何信息的情况下使用整段不工作的代码来调试它,并神奇地解决所有问题。StackOverflow不是这样工作的。如果您正在进行故障排除,并且您有一个特定的问题可以提供详细信息,那么您可能会得到一些帮助。首先要开始的是查看调试控制台中报告的错误并从那里开始。附带说明,如果您的老师没有教您如何使用调试工具,而b无法帮助您跟踪这些语法错误,我建议换老师。我不是要你帮我修改代码,只是想告诉我,如果你看到有什么东西像Arvind那样大声对你说它错了。请帮助教授OP如何自己看到这些错误,而不是将我们用作语法检查器。我修复了语法错误,它仍然在做同样的事情仍在提交表单,但未完成错误检查。另外,当我点击框时,框中的默认文本应该被清除,但这并没有完成。是的,我发现返回错误,修复了语法错误,并使其正常工作。我非常感谢您的帮助。@Phibermatrix,我很高兴它帮助了您。