document.write替换页面内容

时间:2017-05-06 02:13:30

标签: javascript jquery html

每当我尝试使用document.write时,它会替换当前的html页面内容,例如我有 HTML

var notif = document.write("<div class = 'bg' style = 'height:250px; width:400px; z-index:10; background:red;'>Good Morning!</div>");
 $('body').append(notif).delay(5000).fadeOut()

jQuery

{{1}}
这个替换整个页面的大Hello你好 jQuery会在5秒后消失然后什么都不显示?

1 个答案:

答案 0 :(得分:0)

追加&#39>不需要document.write (document.write将内容写入页面,完全替换现有内容)。请参阅jquery append的文档:http://api.jquery.com/append/

你必须写

var notif = "<div class = 'bg' style = 'height:250px; width:400px; z-
index:10; background:red;'>Good Morning!</div>";
$('body').append(notif).delay(5000).fadeOut()
相关问题