标签: jquery-validate

jQuery检查返回的数据对象是否为空

$("#post").live("click",function()
{
    $("input:checkbox[name='bookmarkid']:checked").each(function()
    {
         $.post("php/socialbookmark-post.php", {bookmarkID: $(this).val()},function(data)
         {
              if(data != "") alert(data);
         });
    });
});
Run Code Online (Sandbox Code Playgroud)

只有出现问题时,php文件才输出一些文本.如果数据为空并且显示空消息,则检查我失败.我需要解决这个问题.有任何想法吗?

javascript jquery jquery-validate

1
推荐指数
1
解决办法
2万
查看次数

在jQuery Validation插件的错误模板中插入一个元素

我正在为我的表单使用jQuery Validation插件.它允许您更改errorElement并使用包装器选项包装 errorElement .但是,我想 errorElement中插入一个元素,如下所示:

<label class="error"><em></em>Error message goes here</label>

有没有简单的方法来完成插入em标签?


我尝试使用errorPlacement选项(见下文)预先添加em标签,但似乎插件正在替换errorElement的内容.

$.validator.setDefaults({
    errorPlacement: function(error, element) {
        error.prepend('<em/>');
        error.insertBefore(element);
    }
});
Run Code Online (Sandbox Code Playgroud)


我还尝试使用showErrors选项预先添加em标签(见下文).再次,似乎插件后来正在替换errorElement的内容.

$.validator.setDefaults({
    showErrors: function(errorMap, errorList) {
        for (var i = 0; i < errorList.length; i++) {
            var error = errorList[i],
                $label = this.errorsFor(error.element),
                $element = $(error.element);

            if ($label.length && $label.find('em').length == 0) {
                $label.prepend('<em/>');
            }
        }

        this.defaultShowErrors();
    }
});
Run Code Online (Sandbox Code Playgroud)


我也尝试修改插件,以便在生成错误元素时,<em>标记被预先添加.这有效,直到我专注于有错误的表单元素,然后删除em标记.(这是因为当我在字段中聚焦和/或键入时,jQuery验证不断更新错误元素的内容,因此擦除了在创建错误元素时添加的em标记.)

validation jquery jquery-plugins jquery-validate

1
推荐指数
2
解决办法
4677
查看次数

如何在我的情况下动态更改HTML元素?

我的页面上有一组单选按钮:

<form ...>
   <input type="radio" name="people" checked> Student
   <input type="radio" name="people"> Teacher
   <input type="radio" name="people"> Assistant

   <!-- Here is the dynamic content, which could be check boxes or radio buttons-->
</form>
Run Code Online (Sandbox Code Playgroud)

我想要实现的功能是:

  • 根据单选按钮的选择,单选按钮后的内容动态更改.(单选按钮和内容在表单内.)

例如:

  1. 如果选择" 学生 ",则动态内容部分为(复选框):

    <input type="checkbox" name="name" /> Name <br />
    <input type="checkbox" name="Age" /> Age <br />
    <input type="checkbox" name="grade" /> Grade <br />
    
    Run Code Online (Sandbox Code Playgroud)
  2. 如果选择" 教师 ",则动态内容部分为(复选框和单选按钮):

    <input type="checkbox" name="subject" /> Subject <br />
    
    <input type="radio" name="code" checked> 111
    <input type="radio" name="code"> …
    Run Code Online (Sandbox Code Playgroud)

html javascript jquery jquery-validate jquery-selectors

1
推荐指数
1
解决办法
1795
查看次数

jQuery linkbutton错误

这个jquery函数适用于按钮提交但不适用于链接按钮.为什么?

<html>
<head>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#form1").validate({
                rules: {
                    <%= txtUserName.UniqueID %>: {minlength: 5, required: true},
                    <%= txtPassword.UniqueID %>: {minlength: 5, required: true},
                    <%= txtEmail.UniqueID %>: {required: true},
                    <%= txtURL.UniqueID %>: {required: true},
                    <%=  chkbox.UniqueID%>: {required:true},
                    <%= textcredit.UniqueID %>:{required:true},
                 }, 
                messages: {
                    <%= txtUserName.UniqueID %>: {
                        required: "Plaese enter your name",
                        minlength: "User name must be atleaet of 5 characters"
                    },
                    <%= txtPassword.UniqueID %>: { 
                        required: "Plaese enter your password", 
                        minlength: "Password must be atleaet of 5 characters"
                    }, …
Run Code Online (Sandbox Code Playgroud)

asp.net jquery linkbutton jquery-validate

1
推荐指数
1
解决办法
651
查看次数

jQuery:如何在ajaxForm函数中包括验证?

有人问过这个问题,但尚未确认答案。我尝试过,但是没有用。因此,我想再次问同样的问题(这合适吗?如果不合适,请告诉我该怎么做)。

我有一个需要验证的表单,然后使用ajaxForm提交(该表单包含图像和文件数据,因此使用提交.serialize()将不起作用)。详细信息如下:

HTML:

<form id="myForm" action="..." method="post" enctype="multipart/form-data">
  ...
  <input type="file" name="image" /><br />
  <input type="file" name="file" /><br />
  ...
</form>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$(document).ready(function() {

  $("#myForm").ajaxForm ({

    beforeSubmit: function() {
      $("#myForm").validate({
        onkeyup:false,
        rules: {
          ...
        },
        messages: {
          ...
        },
      });
    },

    success: function(returnData) {
      $('#content').html(returnData);
    }

  });

});
Run Code Online (Sandbox Code Playgroud)

ajaxForm部分没问题。但是,表单只是未经验证而提交。

jquery jquery-validate ajaxform

1
推荐指数
1
解决办法
1万
查看次数

jQuery移动表单验证没有结果

我正在尝试学习jQuery Mobile的jQuery表单验证.我一直看到这个教程,我试图复制,但必须在资源链接上做错了导致html看起来不错.理论上,当用户点击进入并且电子邮件和密码字段为空时,应该出现一条消息,告诉用户"此字段是必需的".

这是整个代码:

<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<script type="text/javacsript">
    $( "#frmLogin" ).validate({
        submitHandler: function( form ) {
            alert( "Call Login Action" );
        }
    });


</script>
<style type="text/css">
label.error {
    color: red;
    font-size: 16px;
    font-weight: normal;
    line-height: 1.4;
    margin-top: 0.5em;
    width: 100%;
    float: none;
}

@media screen and (orientation: portrait){
    label.error { margin-left: 0; display: block; }
}

@media screen and (orientation: landscape){
    label.error { display: inline-block; …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-validate jquery-mobile

1
推荐指数
1
解决办法
5064
查看次数

jQuery Validate插件 - 如何在键入时自动验证?

我正在使用jQuery Validation Plugin来验证客户端的表单.

我的一个要求是表单必须在输入或textarea字段中验证为客户端类型. jQuery Validation Plugin有一个选项onkeyup,但它与没有它的情况相同.

出于测试目的,我创建了jsfiddle演示.

可以做些什么?

javascript jquery jquery-validate

1
推荐指数
1
解决办法
1784
查看次数

jquery验证插件.更改错误样式

我有一个现有的表格,其中的字段非常接近.我想在一个小弹出窗口中获取错误消息,而不是在字段旁边的常规标签.

更确切地说,这是我想要的错误消息样式.

在此输入图像描述

有关如何查找应用于错误消息的样式以及如何更改它们的任何线索?

提前致谢.

css jquery jquery-validate

1
推荐指数
1
解决办法
3万
查看次数

多阶段表单上的jquery验证

我有这个多步骤表格,我想验证(以确保指定正确格式的视频文件,并填写所有必填字段).我想使用jquery.validate插件来实现这一点.

问题是在我添加此验证代码之前,"上传"按钮工作正常.我相信我的代码出了问题导致"上传"按钮停止工作.我在这里包括一个小提琴:http://jsfiddle.net/NZr4n/

我相信这是导致错误的部分.有人可以帮忙吗?

$('#msform').validate({
            rules: {    
                videoFile: {
                    required: true,
                    extension:'mov|mp4|mpeg|wmv'
                }
                videoTitle: {
                    required: true,
                }
                videoDescription: {
                    required: true,
                }
            },
            messages: {
                videoFile: "Please specify a file",
                videoTitle: "Title is required"
                videoDescription: "Description is required"
            }
        });

        if ((!$('#msform').valid()) {
            return false;
        }
Run Code Online (Sandbox Code Playgroud)

javascript jquery jquery-validate

1
推荐指数
1
解决办法
9288
查看次数

在其他方法jquery validate中使用正则表达式处理特殊字符

我有不同的密码验证规则.他们中的大多数工作正常,但特殊字符的一个是有点棘手的.规则说:密码必须至少包含一个特殊字符(来自特殊字符列表).我创建了jquery validate的附加方法来处理这个问题,但由于某种原因,列表外的字符被视为有效.

例如:

  • 654321Ab /有效,因为/是可接受的特殊字符
  • 654321Ab /°必须无效,因为°不是有效的特殊字符,但现在它被视为正确

这是我的jsfiddle:http://jsfiddle.net/o6L3s14c/

我的脚本为附加方法:

$.validator.addMethod("pwcheckspechars", function (value) {
    return /[!@#$%^&*()_=\[\]{};':"\\|,.<>\/?+-]/.test(value)
}, "The password must contain at least one special character");
Run Code Online (Sandbox Code Playgroud)

javascript regex jquery jquery-validate

1
推荐指数
1
解决办法
4312
查看次数