Jquery 使用prev作为远程选择器 我正在使用Zurb基金会,这可能是我得到这个问题的原因。 以下是我的HTML代码: <div class="row collapse"> <label for="">Login</label> <div class="large-1 medium-1 small-2 columns"> <span class="prefix"><i class="fa fa-user"></i></span> </div> <div class="large-11 medium-11 small-10 columns"> <input type="text" /> </div> </div>

Jquery 使用prev作为远程选择器 我正在使用Zurb基金会,这可能是我得到这个问题的原因。 以下是我的HTML代码: <div class="row collapse"> <label for="">Login</label> <div class="large-1 medium-1 small-2 columns"> <span class="prefix"><i class="fa fa-user"></i></span> </div> <div class="large-11 medium-11 small-10 columns"> <input type="text" /> </div> </div>,jquery,Jquery,知道我能做什么吗 非常感谢 使用最接近的方法遍历整个容器 使用find搜索跨度 $'input'.focusfunction{ $this.closest'.row'.find'.prefix'.addClass'prefix-focus'; }; .前缀焦点{ 背景:绿色; } 登录 在前缀中 您也可以像这样直接访问该范围 $'input'.focusfunction{ $'span.prefix'.addClass'prefix-focus'; }; .前缀焦点{ 颜色:F89A0C;

知道我能做什么吗

非常感谢

使用最接近的方法遍历整个容器 使用find搜索跨度 $'input'.focusfunction{ $this.closest'.row'.find'.prefix'.addClass'prefix-focus'; }; .前缀焦点{ 背景:绿色; } 登录 在前缀中 您也可以像这样直接访问该范围

$'input'.focusfunction{ $'span.prefix'.addClass'prefix-focus'; }; .前缀焦点{ 颜色:F89A0C; } 登录 文字颜色
如果答案不起作用,或者您仍然面临麻烦,请告诉我,以便我能提供帮助。谢谢阿马尔,这非常有效。我现在有另一个问题,但我将创建另一个主题。最亲近的人比父母好。
$('input').focus(function() {
    $(this).prev('.prefix').addClass('prefix-focus');
});