本文實例講述了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.VeVB.COm/code/HtmlJsRun
在線HTML/CSS/JavaScript前端代碼調試運行工具:
http://tools.VeVB.COm/code/WebCodeRun
更多關于jQuery相關內容可查看本站專題:《jQuery常見事件用法與技巧總結》、《jQuery常用插件及用法總結》、《jQuery操作json數據技巧匯總》、《jQuery擴展技巧總結》、《jQuery常見經典特效匯總》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答