php - 使用 jQuery 阻止表单提交

标签 php jquery joomla2.5

我正在使用 jquery 验证我的表单,如下所示:

jQuery(document).ready(function(){
        jQuery('#adminform').validate({

        rules: {
          name: {
            minlength: 5,
            maxlength: 30,
            required: true
          },
          username: {
            required: true,
            minlength: 5,
            maxlength: 30
          }
        },
        highlight: function(label) {
            jQuery(label).closest('.control-group').addClass('error');
        },
        success: function(label) {
            label
                .text('OK!').addClass('valid')
                .closest('.control-group').addClass('success');
        },
        messages:{

          name: {
            required: "Enter your name"
          },
          username: {
            required: "Enter a username"
          } 
       }
      });     
});

如果不符合规则,我该如何阻止表单提交?

当我点击提交按钮时,什么都不会发生。

最佳答案

要停止提交表单,您可以使用:

return false;

当您知道输入无效时。

关于php - 使用 jQuery 阻止表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14019113/

相关文章:

php - 忽略 csv 文件的最后一行

javascript - 如何判断图片是否超链接?

使用 Joomla CMS 进行 jQuery 验证

joomla - 将 Joomla 网站改版为 Google 搜索引擎

php - 通过 url 传递 json 数组在 IE 中不起作用

PHP 文件修改时间使用 GMT 偏移设置来报告正确的时间

javascript - 尝试使用 Chart.js 设置刻度刻度 beginAtZero 不成功,为什么?

javascript - 从 <div> 添加/删除 <button>?

javascript - 将时间缩放添加到折线图 (Chart.js)

jquery - 页面 : Close all other tabs when another is opened 上有多个 jQuery UI 选项卡