jQuery验证 - 单击“提交”按钮时,会多次显示相同的消息

时间:2012-12-18 06:32:05

标签: jquery jquery-validate

我在我的网站上实现了jQuery Validation插件。当我单击“提交”按钮而不填写必填文本框时,则会多次显示所需的字段消息。

就像我点击提交按钮三次,然后消息显示三次。它应该只显示一次。

代码

$(document).ready(function()
{
$("#frm").validate(
  {
    rules : {
      cat_name : {
        required: true
      },
      cat_description : {
        required : true
      }
    },
    messages : {
      cat_name : {
        required:"<br />Please enter category name"
      },
      cat_description : {
        required:"<br /> Please enter category description"
      }
    }
  });

});


HTML

<table width="99%" cellspacing="6" cellpadding="3" border="0" align="right">
    <form method="post" action="save_livefeed_categories.php" class="cmxform" id="frm" name="frm">
        <tbody>
            <tr>
                <td><div align="center" class="venueError" id="venueError"></div></td>
            </tr>
                <input type="hidden" value="0" id="update" name="update">
                <input type="hidden" value="" id="cat_id" name="cat_id">
            <tr>
                <td height="10" colspan="2"></td>
            </tr>
            <tr>
                <td width="22%" height="25" bgcolor="#FFFFFF"><strong>Category Name :</strong></td>
                <td width="50%" bgcolor="#FFFFFF"><input type="text" value="" id="cat_name" name="cat_name"></td>         
            </tr>
            <tr>
                <td width="22%" height="25" bgcolor="#FFFFFF"><strong>Category Description :</strong></td>
                <td width="50%" bgcolor="#FFFFFF"><textarea cols="35" rows="8" id="cat_description" name="cat_description"></textarea></td>
            </tr>
            <tr>
                <td bgcolor="#FFFFFF" align="right"></td>
                <td bgcolor="#FFFFFF" align="left">
                    <input type="image" name="Save" id="Save" src="images/bt_save.gif">
                    &nbsp;&nbsp;
                    <input type="image" style="cursor:pointer" onclick="javascript:window.location.replace('livefeed_categories.php'); return false;" src="images/bt_cancel.gif">
                </td>
            </tr>

        </tbody>
    </table>
</form>



输出 jQuery Error

1 个答案:

答案 0 :(得分:0)

这是因为我在<form>标记内添加了<table>标记。现在它的工作正常。

感谢您的时间。