我做一个登陆界面,用onclick()响应servlet为什么不好使呢,可以响应普通JSP页面
<script type="text/javascript">
function func() { if(username.value==""||password.value=="")
{
alert("用户名或密码不能为空");
return;
}
form1.submit();
}
</script>
</head>
<body>
<table align="center" border="1">
<tr>
<td>请输入您的姓名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>输入您的密码:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr align="center">
<td colspan="2">
<input type="reset" value="重置">
<input type="button" value="登陆" onclick="func()">
</td>

</tr>
</table><form action="register" name=form1  >
</form>

解决方案 »

  1.   

    1、请把包含文本框的html片段放入form表单内
    2、请用正确的dom操作方式,getElementById...
      

  2.   


    function func() {if(document.getElementById("username").value==""||document.getElementById("password").value=="")
    {
    alert("用户名或密码不能为空");
    return;
    }
    document.form1.submit();
    }<form action="register" name=form1 >
    <table align="center" border="1">
    <tr>
    <td>请输入您的姓名:</td>
    <td><input type="text" name="username" id="username"/></td>
    </tr>
    <tr>
    <td>输入您的密码:</td>
    <td><input type="password" name="password" id="password"/></td>
    </tr>
    <tr align="center">
    <td colspan="2">
    <input type="reset" value="重置">
    <input type="button" value="登陆" onclick="func()">
    </td></tr>
    </table>
    </form>