jquery字段验证onblur(mvc) [英] Jquery Field Validation onblur (mvc)

查看:175
本文介绍了jquery字段验证onblur(mvc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在用户点击它们之后验证我表单中的字段。但是,我不熟悉使用Jquery进行客户端验证。任何人都可以解释如何验证该字段不是空的吗?

 < label id =lblAccountName>帐户名称< /标签> 
@ Html.TextBoxFor(model => model.Pharmacy.AccountName,new {@id =txtAccountName,@Name =txtAccountName})
解决方案

这可以通过JS实现

  

code> var accName = document.getElementById('txtAccountName');
accName.addEventListener('blur',function(){
if(accName.value!=){
//做某事
}
}) ;

更新
或在jQuery中:

  var accName = $(#txtAccountName); 
accName.blur(function(){
if(accName.val()!=){
//做某事
}
});


I want to have the fields in my form be validated after the user clicks out of them. However, I am not familiar with client side validation using Jquery. Can anyone explain how to validate that the field is not empty?

<label id="lblAccountName">Account Name</label>
@Html.TextBoxFor(model => model.Pharmacy.AccountName, new { @id = "txtAccountName", @Name = "txtAccountName" })

解决方案

This can be achieved with JS

var accName = document.getElementById('txtAccountName');
accName.addEventListener('blur', function () {
    if (accName.value != "") {
        //do something
    }
});

Updated Or in jQuery:

var accName = $("#txtAccountName");
accName.blur(function () {
    if (accName.val() != "") {
        //do something
    }
});

这篇关于jquery字段验证onblur(mvc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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