Jquery验证仅在需要MVC时工作 [英] Jquery Validation only working when required MVC

查看:99
本文介绍了Jquery验证仅在需要MVC时工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我只是想知道是否有人知道为什么Jquery Validation仅在必需属性设置为true时才起作用?所以基本上我想做的就是检查用户在提交之前在屏幕上的字段中输入了一个数字。



来自我帮助者的生成的Html。 />

 <   div     class   = 表单组 >  
< label class = control-label col-lg-4 for = MaxUploadSpeed > 最大上传速度< / label >
< div class = col-lg-8 >
< 输入 class = form-control data-val = true data-val-number = 字段最大上传速度必须是数字。 id = MaxUploadSpeed 名称 = < span class =code-keyword> MaxUploadSpeed type = 数字 = / >
< / div >
< / div >





Jq uery验证码

 $(' #block-validate ')。验证({
规则:{

编号:{
required: false
number: true
},
date:{
required: true
}
});





当需要设置为是的,所以我只是想知道是否有人知道我在这里做错了什么。先谢谢了。

解决方案

' #block -validate')。validate({
rules:{

number:{
required: false
number: true
},
date:{
required: true
}
});





如果需要,这一切都正常设置为true所以我只是想知道是否有人知道我在这里做错了什么。在此先感谢你们。


你在jquery验证中使用了类型号而不是输入标签的ID

所以需要将控件ID更改为MaxUploadSpeed你在你的jquery验证码中错过了}我修改了代码,如下所示

 


#block-validate')。validate({
rules:{

MaxUploadSpeed:{
required: false
number: true
},
日期:{
required: true
}
}});







对于Love演示,你可以在这里看到:

http://jsfiddle.net/anomepa ni / MuV4J / 3 / [ ^ ]


Hey guys, I'm just wondering if anyone knows why the Jquery Validation is only working when the required attribute is set to true? So basically all I want to do is check that the user entered a number in to the field on screen before submitting the from.

Generated Html from my helper.

<div class="form-group">
   <label class="control-label col-lg-4" for="MaxUploadSpeed">Max Upload Speed</label>
<div class="col-lg-8">
   <input class="form-control" data-val="true" data-val-number="The field Max   Upload Speed must be a number." id="MaxUploadSpeed" name="MaxUploadSpeed" type="number" value="" />
</div>
</div>



Jquery Validation code

  $('#block-validate').validate({
        rules: {

        number: {
                required : false,
                number: true 
        },
        date :{
            required :true
        }
});



All this works fine when the required is set to true so I'm just wondering if anyone knows what I'm doing wrong here. Thanks in advance guys.

解决方案

('#block-validate').validate({ rules: { number: { required : false, number: true }, date :{ required :true } });



All this works fine when the required is set to true so I'm just wondering if anyone knows what I'm doing wrong here. Thanks in advance guys.


You have used type number in jquery validation instead of ID of the input tag
so need to change number with ID of control as MaxUploadSpeed and you missed "}" in your jquery validation code I have fix code and as below


('#block-validate').validate({ rules: { MaxUploadSpeed: { required : false, number: true }, date :{ required :true } }});




For Love demo you can see here :
http://jsfiddle.net/anomepani/MuV4J/3/[^]


这篇关于Jquery验证仅在需要MVC时工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆