0

行 onclick="return Val();" 显示错误无法从函数或方法外部返回,并且在执行 JavaScript 函数后,表单将被提交,无论文本字段是否为空白。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
            pageEncoding="ISO-8859-1"%>



        <html>
        <%if(session.getAttribute("status")==null){
            response.sendRedirect("atmHomeUser.jsp");
        }
            %>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Insert title here</title>
        <script>

                function Val(){
                    document.getElementById("m1").innerHTML="";
                    document.getElementById("m2").innerHTML="";
                    if(document.forms[0].oldPin.value.length == 0 || isNaN(document.forms[0].oldPin.value)){
                        document.getElementById("m1").innerHTML="Enter Old pin which must be numbers only";
                            return false;                 
                     }
                    else if(document.forms[0].newPin.value.length == 0 || isNaN(document.forms[0].newPin.value)){
                        document.getElementById("m2").innerHTML="Enter New pin  which must be numbers only";
                        return false;                 
                 }
                    else{
                        return true;
                        }
                    }
        </script>
        </head>
        <body>
            <table width="100%" height="100%">
                <tr>
                    <td colspan="2"><%@include file="atmAdmin.jsp"%>
                    </td>
                </tr>
                <tr height="100%">
                    <td colspan="2" align="center">
                        <div style="">Enter old and new PIN</div>
                        <table style="font-family: verdana font-size : 38px" align="center">

                            <tr>
                                <td></td>
                            </tr>
                            <form action="ChangePIN" method="post">
                            <tr>
                                <td font-size="28px">Enter Old PIN No.</td>
                                <td><input type="name" name="oldPin">
                                </td><td><span id="m1" ></span>
                                    </td>
                            </tr>
                            <tr>
                                <br>
                                <td></td>

                            </tr>
                            <td></td>
                            </tr>
                            <tr>
                                <td font-size="28px">Enter New Pin</td>
                                <td><input type="name" name="newPin">
                                </td><td><span id="m2" ></span>
                                    </td>
                            </tr>
                            <tr>
                                <br>
                                <td></td>
                                <td align="center"><input type="submit" value="submit" onclick="return Val();">
                                </td>
                            </tr>
                            </form>
                        </table></td>
                </tr>
                <tr width="22px" valign="bottom">
                    <td colspan="2"><%@include file="atmFoot.jsp"%>
                    </td>
                </tr>
            </table>


        </body>
        </html>

请帮助我,因为我是新手。还告诉我如何将 javascript 代码转换为 jquery。

4

1 回答 1

0

采用

<form action="ChangePIN" method="post" onsubmit="return Val()">

<input type="submit" value="submit">

检查这个小提琴

于 2013-09-16T09:50:42.220 回答