简体   繁体   English

jQuery在5秒后将onclick隐藏后显示div

[英]Jquery show div after hiding it onclick after 5 seconds

Hey so I have a div that I want to replaceWith some text after clicking on the button and then re-show the same hidden text after 5 seconds. 嘿,所以我有一个div,我想在单击按钮后用一些文本替换,然后在5秒后重新显示相同的隐藏文本。 I am stuck on the part where I need to re-show it. 我被困在需要重新显示的部分。 I hid the div with the onclick function and appended some text but after a couple seconds I would like to re-show the original text. 我用onclick函数隐藏了div,并添加了一些文本,但是几秒钟后,我想重新显示原始文本。

here is the link that I need to change text onclick and then after 5 seconds show the ORIGINAL text... 这是我需要更改onclick文本的链接,然后在5秒钟后显示原始文本...

originally the text says "add to calendar", upon clicking it, it should change to "calendar updated" and then after 5 seconds change back to "add to calendar". 最初,文本显示为“添加到日历”,单击后应更改为“日历更新”,然后在5秒钟后更改回“添加到日历”。

<div class="resSubmitAction download resDetailsButton">
    <a href="javascript:void(0);">
</div>
<div class="calText"><p>add to calendar</p></div></a>
</div>

Jquery: jQuery:

$(document).ready(function () {
     $(".resSubmitAction").click(function () {
         $(".calText > p").replaceWith("Calendar Updated");
     });
 });

Make use of the setTimeout function. 利用setTimeout函数。 Fiddle 小提琴

$("#clickme").click(function(){
    var elem = $(this);
    setTimeout(function(){
        elem.hide();        
    }, 5000);
});

In the code that you provided, the click event is not attached correctly, if you click 'add to calendar' it doesn't trigger the event. 在您提供的代码中,click事件未正确附加,如果您单击“添加到日历”,则不会触发该事件。

You can use the setTimeout function to call any function after certain time delay, this is your code with the setTimeout implemented. 您可以使用setTimeout函数在一定的时间延迟后调用任何函数,这是实现了setTimeout的代码。 Fiddle 小提琴

 $(".calText").click(function () {
     var originalText = $(".calText > p").text();
     $(".calText > p").text("Calendar Updated");

     setTimeout(function(){ 
             $(".calText > p").text(originalText) 
     }, delayTime);

     //Just a little timer I added
     triggerTimer();
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM