【问题标题】:jquery countdowntimer on submitjquery 倒计时提交
【发布时间】:2013-03-25 07:40:57
【问题描述】:

我想在访问者点击提交时编码,它会在重定向到所述站点之前显示倒计时时间。

下面是演示

http://jsfiddle.net/VJT9d/17/

这是html代码:

<input id="hulk" class="submit" name="send_contact" type="submit" value="Send" />

<div style="display:hidden">Redirecting In <span id="countdown">5</span>.</div>

和jquery代码:

var timer = 5,
el = document.getElementById('countdown');

$('#hulk').click(function t_minus() {
'use strict';
el.innerHTML = timer--;
if (timer >= 0) {
    setTimeout(function () {
        t_minus();
    }, 1000);
} else {
    window.location.replace("/");
}
}());

如何让倒计时只在点击提交后出现?

【问题讨论】:

    标签: jquery redirect onclick submit


    【解决方案1】:

    只需删除您最后的()

    var timer = 5,
        el = document.getElementById('countdown');
    
    $('#hulk').on( 'click', function t_minus() {
        'use strict';
        el.innerHTML = timer--;
        if (timer >= 0) {
            setTimeout(function () {
                t_minus();
            }, 1000);
        } else {
            window.location.replace("/");
        }
    });
    

    更新fiddle

    【讨论】:

      【解决方案2】:

      要使消息仅在单击后可见,您需要做两件事:首先,正确隐藏具有适当样式的元素,其次不要在最后一行启动 t_minus 函数!

      solution

      var timer = 5,

      el = document.getElementById('countdown');
      $('#hulk').click(function t_minus() {
      'use strict';
      el.innerHTML = timer--;
      if (timer >= 0) {
          setTimeout(function () {
          t_minus();
          }, 1000);
      } else {
          window.location.replace("/");
      }
      });
      

      请阅读如何使用 CSS 隐藏元素

      【讨论】:

        【解决方案3】:

        使用

        $('#countdown').show()

        点击函数内部。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-09-04
          • 1970-01-01
          • 1970-01-01
          • 2011-05-08
          • 1970-01-01
          • 1970-01-01
          • 2015-01-31
          • 2011-12-08
          相关资源
          最近更新 更多