更改实时验证的错误消息

时间:2011-04-21 03:23:00

标签: javascript validation

var Validate = {

/**
 *  validates that the field has been filled in
 *
 *  @var value {mixed} - value to be checked
 *  @var paramsObj {Object} - parameters for this particular validation, see below for details
 *
 *  paramsObj properties:
 *                          failureMessage {String} - the message to show when the field fails validation 
 *                                                    (DEFAULT: "Can't be empty!")
 */
Presence: function(value, paramsObj){
    var paramsObj = paramsObj || {};
    var message = paramsObj.failureMessage || "Can't be empty!";
    if(value === '' || value === null || value === undefined){ 
        Validate.fail(message);
    }
    return true;
},

实际上我试图在这里改变paramobj 我写的是

    try{
        Validate.Presence(true,{ failureMessage: "You must be true!" })
    }catch(err){
        alert(err.description);
    }

为什么返回警报未定义? 导致错误的原因是什么?

1 个答案:

答案 0 :(得分:0)

尝试使用:

 alert(err.message);