New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化:支持完全自定义消息的DOM结构 #44

Closed
niceue opened this Issue Sep 25, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@niceue
Copy link
Owner

niceue commented Sep 25, 2013

消息的结构,消息的样式,消息的显示方式。

0.5.0版本作了以下优化:

  1. 去掉了msgTemplate这个用处不大的参数
  2. 增加参数msgWrapper,用于设置消息容器的标签
  3. 增加参数msgMaker,用于完全自定义消息的结构

看下面的例子:

$('#demo').validator({
    fields: {
        'user[name]': 'required;username'
        ,'user[pwd]': 'required;password'
    },
    msgWrapper: 'div',
    msgMaker: function(opt){
        return '<span class="'+ opt.type +'">' + opt.msg + '</span>';
    }
});

最后自动生成的消息为:

<div class="msg-box n-right" for="user[name]">
    <span class="n-error">不能为空</span>
</div>

msgMaker方法的参数opt包含以下选项:

  • type:消息类型(可能的值为:error / ok / tip / loading)
  • cls: 即msgClass参数的值
  • style: 即msgStyle参数的值
  • icon: 即msgIcon参数的值
  • arrow: 即msgArrow参数的值
  • show: 即msgShow参数的值
  • hide: 即msgHide参数的值

@ghost ghost assigned niceue Sep 25, 2013

@niceue niceue closed this Oct 3, 2013

@aidybnt

This comment has been minimized.

Copy link

aidybnt commented Sep 12, 2016

感谢大神提供这么好的程序。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment