日期:2014-05-16  浏览次数:20497 次

jsp中回车提交表单

js方法:

   function tijiao() {
        var loginForm = document.getElementById("loginForm");
        if (loginForm.login_name.value == "") {
            alert("帐号必须输入");
            return;
        }
        if (loginForm.pwd.value == "") {
            alert("密码必须输入");
            return;
        }
        if (loginForm.validatacode.value == "") {
            alert("校验码必须输入");
            return;
        }

        loginForm.action = "<%=path%>/memberlogin.action";
        loginForm.submit();
    }

?


jsp代码:

  <form id="loginForm" method="post" onsubmit="javascript:tijiao()">

                <ul>
                    <li class="login_L_1"></li>
                    <li class="login_L_2">
                        <div align="center">${errMsg}</div>
                        <p>登录类型:
                            <select name="login_type">
                                <option value="loginname">用户名</option>
                             
                        <option value="email">电子邮箱</option>
                            </select>
                        </p>
                        <p>登录名:<input type="text" value="" name="login_name" size="27"/></p>

                        <p>密 码:<input type="password" value="" name="pwd" size="27"/></p>

                        <p>验证码:<input type="text" value="" name="validatacode" size="10"/>
                            <img src="<%=path %>/getImage.action" id="validataimage" border="0"/>
                        </p>


                        <p>
                            <input type="submit" name="Submit" value="登 录"  onclick="javascript:tijiao();"
                                   class="blueButtonCss"/>  
                            <input type="button" name="Submit3" value="忘记密码" onclick="javascript:chongzhi();"
                                   class="blueButtonCss"/>
                        </p>
                    </li>
                    <li class="login_L_3"></li>
                </ul>

            </form>

?<form>标签中加上onsubmit 对应的提交的按钮 type设为submit就可以以回车方式提交了