jQuery实现文本显示一段时间后隐藏的方法分析

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

jQuery实现文本显示一段时间后隐藏的方法分析

longzhoufeng   2020-05-17 我要评论

本文实例讲述了jQuery实现文本显示一段时间后隐藏的方法。分享给大家供大家参考,具体如下:

点击button时,提示信息显示,8秒后,信息隐藏。

<input id="place_order" name="place_order" type="submit" />
<div class="after_submit_remind" style="display: none;">
  请耐心等待,这段文本显示8秒后会消失,安拓网络。
</div>

jQuery(document).ready(function(){
  jQuery(document).on('click', 'input#place_order', function(){
    jQuery(".after_submit_remind").show().delay(8000).hide(0);
  });
});

扩展:令时间每秒自动减1;

将text中的“8”改为“9”;

jQuery(document).on('click', 'input#place_order', function(){
  jQuery(".after_submit_remind").show().delay(8000).hide(0);
  jQuery(function (){
    reduceTime();
  });
  function reduceTime() {
    var auto_reduce = jQuery("#auto-time").html();
    if(auto_reduce == 0){
      jQuery("#auto-time").html("9");
    }else{
      jQuery("#auto-time").html(--auto_reduce);
      setTimeout(reduceTime,1000);
    }
  };
});/*显示 8s 的content*/

感兴趣的朋友可以使用如下工具测试上述代码运行效果:

在线HTML/CSS/JavaScript代码运行工具:
http://tools.softyun.net/code/HtmlJsRun

在线HTML/CSS/JavaScript前端代码调试运行工具:
http://tools.softyun.net/code/WebCodeRun

希望本文所述对大家jQuery程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们