0

当我点击提交按钮时没有任何反应,我不确定是什么问题。该程序仅添加 2 个数字,输出应为警报消息。请帮忙

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GlassFish JSP Page</title>
</head>
<body>

    <%
        int a = 6, b = 8, c;
            c=a+b;
    %>
    <p>
            Value 1 =
            <%=a%></p>
    <p>
            Value 2 =
            <%=b%></p>
    <p>
            Enter the value :<br /> <input type="text" id="c" /></br>
                <input type="submit" value="Submit"
                    onclick="validate();" />
    </p>
    <script type="text/javascript">

            function validate() {
                    var a = <%=a%>;
                    var b = <%=b%>;
                    var c = <%=c%>;
                    if (c!= parseInt(document.getElementById("c").value, 10))
                            alert("The values you entered is incorrect.");
                    } else {
                            alert("Correct!");
                    }
            }
    </script>
</body>
</html>
4

1 回答 1

2

您在 if 语句中缺少左括号

if (c!= parseInt(document.getElementById("c").value, 10))

应该

if (c!= parseInt(document.getElementById("c").value, 10)){
于 2012-04-12T21:05:27.443 回答