如何在提交时向Happy.js添加确认消息?

时间:2013-12-15 01:24:04

标签: javascript jquery

我正在使用Happy.js,并希望在span / p元素中显示一条消息,当用户成功填写表单时,该元素将显示在提交按钮下方。我有验证工作,但似乎无法挂钩显示消息。在不愉快的功能下,我试着按下它的手!提前谢谢......

 <p>
    <input type="submit" class="submit myButtons submitButton specificLink button button-block button-rounded button-large" name="submit" value="Submit" placeholder="">
 </p>

 <div id="results" class="results" style="text-align:center;">
    <span>
    <p class="success">Your message was sent succssfully!<br> I will be in touch as soon as I can.
    </p>
   </span>
 </div>

  var dd= $.noConflict();
  dd(document).ready(function () {
    dd('.success').hide();
        dd('#frmContact').isHappy({
            fields: {
              // reference the field you're talking about, probably by `id`
              // but you could certainly do $('[name=name]') as well.
              '#yourName': {
                required: true,
                message: 'Might we inquire your name'
              },
              '#email': {
                required: true,
                message: 'How are we to reach you sans email??',
                test: happy.email // this can be *any* function that returns true or false
              },
              '#comments': {
                required: true,
                message: 'Please leave a message!',
              }
          },
        unHappy: function () {
            var yourName = dd('#yourName').val();
            var email = dd('#email').val();
            var comments = dd('#comments').val();
            if (yourName && email && comments == true){
                  dd('.success').show();
            } 
        },
      });
  });

1 个答案:

答案 0 :(得分:0)

试一试

    function () {
    var yourName = dd('#yourName').val();
    var email = dd('#email').val();
    var comments = dd('#comments').val();
        if (yourName && email && comments == true){
            dd('#results').show();
            dd('.success').show();
        }