Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 不同链接上的Jquery链接_Javascript_Jquery_Chain - Fatal编程技术网

Javascript 不同链接上的Jquery链接

Javascript 不同链接上的Jquery链接,javascript,jquery,chain,Javascript,Jquery,Chain,基本上,我想要实现的是当我鼠标点击“第一个a”链接时,第二个链接将变为红色,当我鼠标点击它时,它将返回蓝色,但我似乎无法使用$('this')来定位它 看看这个JSbin 您需要使用JQuery.next()函数才能访问下一个元素。 希望对您有所帮助您可以试试这个 var link = '.shareButtonsWrapper div a:first'; $('body').on('mouseenter', link, function(){ $(this).next('a').cs

基本上,我想要实现的是当我鼠标点击“第一个a”链接时,第二个链接将变为红色,当我鼠标点击它时,它将返回蓝色,但我似乎无法使用
$('this')
来定位它


看看这个JSbin

您需要使用JQuery.next()函数才能访问下一个元素。 希望对您有所帮助

您可以试试这个

var link = '.shareButtonsWrapper div a:first';
$('body').on('mouseenter', link, function(){
    $(this).next('a').css({"color":"red"});
}).on('mouseleave', link, function(){
    $(this).next('a').css({"color":"blue"});
});


您可以使用next()函数而不是兄弟()函数。

如果您查看OP发布的代码,您会发现我的代码并不复杂。我同意。但“不太复杂”!='简单“看看JSbin
$("a").hover(
    function () {
        $(this).next().css('color', 'red');
    }, 
    function () {
        $(this).next().css('color', 'blue');
    }
);
var link = '.shareButtonsWrapper div a:first';
$('body').on('mouseenter', link, function(){
    $(this).next('a').css({"color":"red"});
}).on('mouseleave', link, function(){
    $(this).next('a').css({"color":"blue"});
});
$('.shareButtonsWrapper div a:first-child').on('mouseenter', function(){
  $(this).siblings().css("color","red");
}).on('mouseleave', function(){
  $(this).siblings().css("color", "blue");
});