Javascript 不同链接上的Jquery链接
基本上,我想要实现的是当我鼠标点击“第一个a”链接时,第二个链接将变为红色,当我鼠标点击它时,它将返回蓝色,但我似乎无法使用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
$('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");
});