忽略Jquery验证

时间:2012-01-20 01:11:42

标签: jquery html jquery-validate

我有他用来编辑用户详细信息的html表单。以下是它的工作原理 - 当点击表格上的名称时,我使用此表单从数据库加载数据,如?id=<theID>

问题在于,因为字段对它们进行了验证,所以除非我输入了所有数据,否则它会阻止我删除该用户。我的问题是:有没有办法让“删除”操作忽略验证并继续删除?

以下是整个代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>

  <style>

* {
    border: medium none;
     /*font-family: "Arial",Helvetica,sans-serif;
    font-size: small;*/
    margin: 0;
    padding: 0;
}
</style>

<style type="text/css">
        pre{background-color: #F5F2EE;}

        label.error {
        color: red;
        padding-left: 3px;
        font-weight: bold;
}
      </style>

    <script type="text/javascript">

        $(document).ready(function() {
            $("#myform").validate({
                rules: {
                    firstname: "required",
                    surname: "required",
                    address1: "required",                     
                    address4: "required",// simple rule, converted to {required:true}
                    address5: "required",                    
                    phone1: "required",
                    email: "required",
                    postcode1: "required",
                    postcode2: "required",
                    email: {                // compound rule
                        required: true,
                         email: true
                    },

                },
                messages: {
                    firstname: " *Required",
                    surname: " *Required",
                    address1: " *Required",                     
                    address4: " *Required",// simple rule, converted to {required:true}
                    address5: " *Required",
                    phone1: " *Required",
                    email: " *Required",
                    postcode1: " *Required",
                    postcode2: " *Required",                                                    
                }
            });
        });

    </script>
</head>



<body>

    <div id="content">
        <div class="about">

            <h2>Check</h2>

<form id="myform" action="" method="POST">
<table style="font-weight:bold; margin-top:5px; border: 1px solid #C6CFE1; padding-left:5px;background-color: #F5F2EE;">    
  <tr>
    <td>

        Name * 
    </td>
    <td>
        <input type="text" name="firstname" id="firstname" >
    </td>
    <td>
        Home Phone * 
    </td>
    <td>
        <input type="text" name="phone1" id="phone1">

    </td>

  </tr>  

  <tr>
    <td>
        Surname * 
    </td>
    <td>
        <input type="text" name="surname" id="surname" >
    </td>

    <td>
        Mobile  
    </td>
    <td>
        <input type="text" name="phone2" id="phone2" value="">
    </td>

  </tr>  

  <tr>
    <td>

        Address 1 *
    </td>
    <td>
        <input type="text" name="address1" id="address1" >
    </td>
    <td>
        Email *
    </td>
    <td>
        <input type="text" name="email" id="email" value="">

    </td>

  </tr>  

  <tr>
    <td>
        Address 2 
    </td>
    <td>
        <input type="text" name="address2" id="address2" value="">
    </td>

    <td>

    </td>
    <td>

    </td>

  </tr>  


<tr>
    <td>
        Address 3
    </td>

    <td>
        <input type="text" name="address3" id="address3" value="">
    </td>
    <td>
        Town *
    </td>
    <td>
        <input type="text" name="address4" id="address4" value="">
    </td>

  </tr>  




                <tr>
                    <td>
                        County *
                    </td>
                    <td>
                        <input type="text" name="address5" id="address5" value="">
                    </td>
                    <td>

                        Postcode *
                    </td>
                    <td>
                       <input type="text" name="postcode1" id="postcode1" size="5"> 
                       <input type="text" name="postcode2" id="postcode2" size="5">
                    </td>

                </tr>  




   <tr>
    <td>
    <input type="hidden" name="ID" value="3257" />
        &nbsp;
    </td>
    <td colspan="4">
        <input type="hidden" name="id" id="id" value="3257">
        <input type="submit" name="submit" id="submit" value="Submit update"> <input type="submit" name="delete" id="delete" value="Delete Record">


    </td>
    <td>     
    </td>
    <td>
        &nbsp;
    </td>
  </tr>  

 </table>
</form>
</body>
</html>

感谢您的协助

1 个答案:

答案 0 :(得分:1)

简单,将class="cancel"添加到删除按钮。这将导致它忽略验证。

可在此处找到更多信息:Ignoring Jquery Validation