jquery - 所有其他的(不是这个)

标签 jquery this

我在同一页面中重复了不同的 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();
});

演示地址:http://jsfiddle.net/8gPCE/11/

关于jquery - 所有其他的(不是这个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10121222/

相关文章:

java - 匿名内部类——获取 "this"

Jquery - 选择空文本输入并为其添加边框

jquery - RequireJS 和 Jquery - 一个文件中有多个模板?

jquery - 使悬停突出显示 FancyTree 中的整个 li 行

javascript - 通过 jQuery 重新加载页面

javascript - 了解 .call 和 .apply 在 Javascript 中的行为

javascript - HTML 按钮 onclick 函数无法使用 jQuery 变量作为参数

java - 使用 'this.methodName' 调用或仅使用 'methodName' 调用类的私有(private)方法之间的区别

c# - this[参数] 语法的用途是什么?

javascript - 使用 "this"的 javascript dojo 闭包中使用的函数 -notation 未定义