我在同一页面中重复了不同的 div。这是简化的示例: http://jsfiddle.net/8gPCE/16/
我尝试做的是:
- 单击绿色,仅单击红色淡出
- 另一个红色淡出
- 当我单击其他任何地方(例如背景)时,所有红色都会淡入
我已经尝试了一个小时,但没有同时找到这三件事。
这样的东西不起作用。(我只是尝试前两件事):
$(function(){
$(".green").click(function() {
$(this).siblings(".red").fadeOut("slow");
$(this).parent().not(this).children(".red").fadeIn("slow");
});
})
最佳答案
这应该可以解决所有问题
$(".green").click(function(e) {
e.stopPropagation();
$(this).siblings(".red").fadeOut("slow");
$('.green').not(this).siblings(".red").fadeIn("slow");
});
$(document).click(function() {
$('.red').fadeIn();
});
关于jquery - 所有其他的(不是这个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10121222/