我有一个 div,里面有一堆 html。我想覆盖它以暂时显示一条消息(让我们说 3 秒),然后轻松回到那里的原始 html。支持这一点的最佳方法是什么?
问问题
85 次
3 回答
4
您所要做的就是将 HTML 作为字符串存储在变量中,然后您就可以恢复。看看这个小提琴。
var myDiv = document.getElementById('demo');
var myOldHtml = myDiv.innerHTML;
myDiv.innerHTML = '<span>Wow, so HTML</span>';
setTimeout(function () {
myDiv.innerHTML = myOldHtml;
}, 1000);
于 2014-01-18T18:20:51.703 回答
1
于 2014-01-18T18:19:57.183 回答
1
看看这个例子我认为它接近你正在寻找的东西
仅供参考,我没有正确检查
http://jsfiddle.net/laelitenetwork/GUxgX/
// Ignore this it's just there to dynamically add a div to DOM
$(document).ready(function(){
$('a').click(function(){
$('.document').html(
'<div id="result">This is a message</div>'
);
});
});
function hideMsg(){
// Hide dynamically added div
setTimeout(function(){
$('#result').slideUp(500);
}, 5000);
}
// Listen DOM changes
$('.document').bind("DOMSubtreeModified", hideMsg);
于 2014-01-18T18:21:22.083 回答