如何“淡出" & “删除" jQuery中的div? [英] How to "fadeOut" & "remove" a div in jQuery?

查看:103
本文介绍了如何“淡出" & “删除" jQuery中的div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使div&的淡入淡出效果单击图像后,删除该div(id ="notification").

I'm trying to give fadeout effect to a div & delete that div(id = "notification"), when an image is clicked.

这就是我的做法:

<a onclick="$("#notification").fadeOut(300,function() { $("#notification").remove(); });" class="notificationClose "><img src="close.png"/></a>

这似乎不起作用. 我该怎么做才能解决此问题?

This seems to not be working. What do I need to do to fix this?

推荐答案

尝试一下:

<a onclick='$("#notification").fadeOut(300, function() { $(this).remove(); });' class="notificationClose "><img src="close.png"/></a>

我认为您在onclick周围加上双引号使它不起作用. :)

I think your double quotes around the onclick were making it not work. :)

编辑:如下所述,内联javascript是有害的,您应该将其从onclick中删除并将其移至jQuery的

EDIT: As pointed out below, inline javascript is evil and you should probably take this out of the onclick and move it to jQuery's click() event handler. That is how the cool kids are doing it nowadays.

这篇关于如何“淡出" &amp; “删除" jQuery中的div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆