重复:How would I implement StackOverflow's hovering dialogs?
我正在尝试创建一条错误消息,正在显示,到目前为止,这是一次粗略的尝试,消息显示正常,但点击不起作用..
function message(somemessage){
$(document).ready(function(){
$('<div class="error">' + somemessage+ '</div>')
.insertAfter( $('#ErrorMessage') ).fadeIn('slow').animate({opacity: 1.0}, 5000).click(function(){$(this).remove});
});
}
答案 0 :(得分:10)
我已经在this question中解答了如何执行此操作。
如果您愿意,可以直接跳到example.
但是,如果你想要更强大的东西,你应该看看那里的许多解决方案:
如果您想了解如何处理本网站中使用的其他通知(获得新徽章时的顶部通知等),您可以查看如何在this question中执行此操作。
答案 1 :(得分:4)
是不是因为你忘了在remove
函数之后添加括号?
试试这个
$('<div class="error">' + "somemessage"+ '</div>')
.insertAfter( $('#ErrorMessage') ).fadeIn('slow').
animate({opacity: 1.0}, 5000).click(function(){$(this).remove()});