嘿,我有一个div,我想在点击按钮后replaceWith一些文本,然后在5秒后重新显示相同的隐藏文本。我被困在需要重新展示的部分。我用onclick函数隐藏了div,并附加了一些文本,但几秒钟后,我想重新显示原始文本。
下面是我需要更改文本的链接,点击5秒后显示原始文本.
原来的文字是“添加到日历”,点击它,它应该更改为“日历更新”,然后在5秒后改为“添加到日历”。
<div class="resSubmitAction download resDetailsButton">
<a href="javascript:void(0);">
</div>
<div class="calText"><p>add to calendar</p></div></a>
</div>Jquery:
$(document).ready(function () {
$(".resSubmitAction").click(function () {
$(".calText > p").replaceWith("Calendar Updated");
});
});发布于 2014-04-16 16:35:58
利用setTimeout函数。小提琴
$("#clickme").click(function(){
var elem = $(this);
setTimeout(function(){
elem.hide();
}, 5000);
});发布于 2014-04-16 17:14:34
在您提供的代码中,没有正确地附加单击事件,如果单击“添加到日历”,则不会触发事件。
您可以使用setTimeout函数在某些时间延迟之后调用任何函数,这是您用setTimeout实现的代码。小提琴
$(".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();
});https://stackoverflow.com/questions/23115126
复制相似问题