Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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更改其他div的背景_Javascript_Jquery - Fatal编程技术网

Javascript 悬停文本时,使用jquery更改其他div的背景

Javascript 悬停文本时,使用jquery更改其他div的背景,javascript,jquery,Javascript,Jquery,当悬停链接时,我试图更改上一个div的背景,但在这里它不起作用,这里是代码,这是我的脚本 $('div a.link').hover(function(){ var icon = $(this).prevAll('div.icon').first(); icon.css({'background':'url(http://www.rangde.org/images/icons/circle_grey_hover.jpg) no-repeat', 'col

当悬停链接时,我试图更改上一个div的背景,但在这里它不起作用,这里是代码,这是我的脚本

$('div a.link').hover(function(){

var icon = $(this).prevAll('div.icon').first();          
          icon.css({'background':'url(http://www.rangde.org/images/icons/circle_grey_hover.jpg) no-repeat', 'color':'#fff','cursor':'pointer'});

 });          
我的html

<div class="icon">1</div>
<div><a href="#" class="link">First article</a></div>
<div class="clearfloat"></div>
<div class="icon">2</div>
<div><a href="#" class="link">Second article</a></div>
<div class="clearfloat"></div>
<div class="icon">3</div>
<div><a href="#" class="link">Third article</a></div>


只要css就可以做到这一点,为什么要使用jQuery?

只要css就可以做到这一点,为什么要使用jQuery?

.icon{background: url(http://www.rangde.org/images/icons/circle_grey.jpg) no-repeat;
width: 92px;
height: 97px;
padding: 35px 0px 0px 45px;
font-size: 14pt;
color: black;
font-weight: 600;
width: 32%;float:left;}
.link{width:60%;float:left;color:#048ccc;font-weight:600;padding-top:30px;}
.clearfloat{clear:both;}
​
 $('div a.link').hover(function(){
     var icon = $(this).parent().prev();          
     icon.css({'background':'url(http://www.rangde.org/images/icons/circle_grey_hover.jpg) no-repeat', 'color':'#fff','cursor':'pointer'});
 }, function() {
     var icon = $(this).parent().prev().css({'background':'none'});
 });           

​