Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

javascript - 如何在jQuery中“淡出”和“删除”一个div?(How to “fadeOut” & “remove” a div in jQuery?)

I'm trying to give fadeout effect to a div & delete that div(id = "notification"), when an image is clicked.(当点击图像时,我正试图将fadeout效果赋予div并删除div(id =“notification”)。)

This is how I'm doing that:(这就是我这样做的方式:) <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?(我需要做些什么来解决这个问题?)   ask by RSilva translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this:(试试这个:)

<a onclick='$("#notification").fadeOut(300, function() { $(this).remove(); });' class="notificationClose "><img src="close.png"/></a> I think your double quotes around the onclick were making it not work.(我认为你在onclick周围的双引号使它无法正常工作。) :)(:)) 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.(编辑 :正如下面所指出的,内联javascript是邪恶的,你应该从onclick取出它并将其移动到jQuery的click()事件处理程序。) That is how the cool kids are doing it nowadays.(这就是酷孩子们现在正在做的事情。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...