0

我有一个jsp表单,当用户输入时提交:以下是我的jsp文件

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page session="false"%>
<html>
<head>
<title>Login</title>
<style type="text/css">
.form-2 {
    /* Size & position */
    width: 300px;
    margin: 60px auto 30px;
    padding: 10px;
    position: relative; /* For the submit button positioning */

    /* Styles */
    box-shadow: 
        0 0 1px rgba(0, 0, 0, 0.3), 
        0 3px 7px rgba(0, 0, 0, 0.3), 
        inset 0 1px rgba(255,255,255,1),
        inset 0 -3px 2px rgba(0,0,0,0.25);
    border-radius: 5px;
    background: linear-gradient(#eeefef, #ffffff 10%);
}

.form-2 h1 .log-in,.form-2 h1 .sign-up {
    display: inline-blue;
    text-transform: inherit;
}

.form-2 h1 .log-in {
    color: blue;
    padding-right: 2px;
}

.form-2 h1 .sign-up {
    color: #ffb347;
    padding-left: 2px;
}
.form-2 .float {
    width: 100%;
    float: left;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,1);
}

.form-2 .float:first-of-type {
    padding-right: 5px;
}

.form-2 .float:last-of-type {
    padding-left: 5px;
}
.form-2 label {
    display: block;
    padding: 0 0 5px 2px;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: 400;
    text-shadow: 0 1px 0 rgba(255,255,255,0.8);
    font-size: 11px;
}

.form-2 label i {
    margin-right: 5px; /* Gap between icon and text */
    display: inline-block;
    width: 10px;
}
.form-2 input[type=text],
.form-2 input[type=password] {
    font-family: 'Lato', Calibri, Arial, sans-serif;
    font-size: 13px;
    font-weight: 400;
    display: block;
    width: 100%;
    padding: 5px;
    margin-bottom: 5px;
    border: 3px solid #ebe6e2;
    border-radius: 5px;
    transition: all 0.3s ease-out;
}
.form-2 input[type=text]:hover,
.form-2 input[type=password]:hover {
    border-color: #CCC;
}

.form-2 label:hover ~ input {
    border-color: #CCC;
}

.form-2 input[type=text]:focus,
.form-2 input[type=password]:focus {
    border-color: #BBB;
    outline: none; /* Remove Chrome's outline */
}
.clearfix:after {
    content: "";
    display: table;
    clear: both;
}


.form-2 input[type=submit],
.form-2 .log-twitter {
    /* Size and position */
    width: 49%;
    height: 38px;
    float: left;
    position: relative;

    /* Styles */
    box-shadow: inset 0 1px rgba(255,255,255,0.3);
    border-radius: 3px;
    cursor: pointer;

    /* Font styles */
    font-family: 'Lato', Calibri, Arial, sans-serif;
    font-size: 14px;
    line-height: 38px; /* Same as height */
    text-align: center;
    font-weight: bold;
}

.form-2 input[type=submit] {
    margin-left: 50%;
    background: linear-gradient(#fbd568, #ffb347);
    border: 1px solid #f4ab4c;
    color: #996319;
    text-align:center;
    text-shadow: 0 1px rgba(255,255,255,0.3);
}

.form-2 .log-twitter {
    margin-right: 1%;
    background: linear-gradient(#34a5cf, #2a8ac4);
    border: 1px solid #2b8bc7;
    color: #ffffff;
    text-shadow: 0 -1px rgba(0,0,0,0.3);
    text-decoration: none;
}
.form-2 input[type=submit]:hover,
.form-2 .log-twitter:hover {
    box-shadow: 
        inset 0 1px rgba(255,255,255,0.3), 
        inset 0 20px 40px rgba(255,255,255,0.15);
}

.form-2 input[type=submit]:active,
.form-2 .log-twitter:active{
    top: 1px;
}
.no-boxshadow .form-2 input[type=submit]:hover {
    background: #ffb347;
}

.no-boxshadow .form-2 .log-twitter:hover {
    background: #2a8ac4;
}
</style>
<script type="text/javascript">
function login(){
    alert("login");
    document.forms[0].action="login";
    document.forms[0].method="post";
    document.forms[0].submit();
}

</script>
</head>
<body>
    <form class="form-2" >

    <table width="100%">
            <tr>
                <td align="center" colspan="2" width="100%"><b>  <h1> <span class="log-in">Login</span></h1></b></td>
            </tr>
            <tr>
                <td align="center" colspan="2" width="100%"></td>
            </tr>
            <tr class="float">
                <td align="right" class="icon-user" width="50%"><label for="login"><i class="icon-user"></i>Username</label> </td>
                <td align="left" class="field" width="50%"><input type="text" name="login" placeholder="Username "></td>
            </tr>
            <tr class="float">
                <td align="right" class="icon-lock" width="50%"><label for="password"><i class="icon-lock"></i>Password</label></td>
                <td align="left" class="field" width="50%"><input type="password" name="password" placeholder="Password" class="showpassword"> </td>
            </tr>
            <tr>
                <td align="right" colspan="2" width="50%"><input type="button"
                    name="CreateContact" value="Login" onclick="login()"/><i class="icon-user"></i></td>
            </tr>
        </table>
        </form>
</body>
</html>

当我提交页面时,它给出了这个例外:

Error: TypeError: login is not a function

请帮我解决这个问题

4

4 回答 4

1

看起来像是login某种 js 对象,尝试重命名该login()函数,它对我有用。

于 2013-03-18T14:10:55.743 回答
1

您必须使用名称登录名或函数名称重命名字段。它与具有相同名称的函数冲突。

工作示例:http: //jsfiddle.net/inser/ccXHd/1/

<td align="right" class="icon-user" width="50%"><label for="login1"><i class="icon-user"></i>Username</label> </td>
                <td align="left" class="field" width="50%"><input type="text" name="login1" placeholder="Username "></td>
于 2013-03-18T14:12:26.717 回答
1

尝试这个

<form class="form-2" action="login" method="post" >


<input type="submit" name="CreateContact" value="Login" />

您可以使用提交按钮并在表单标签中包含操作、方法。

于 2013-03-18T14:04:51.897 回答
-1

相反,你也可以做这样的事情

document.getElementById("idOfButton").onclick = dologin;

正如所有人所说,更改登录功能名称。

PS我刚刚知道答案中有一个预定义的登录功能。

于 2013-03-18T14:02:45.553 回答