2017-01-28 49 views

回答

2

我認爲你需要使用jQuery的方法.stopPropagation()和替換mouseentermouseovermouseleavemouseout

var ids = ['test','wrapper']; 
 

 

 
$.each(ids, function(index, value) { 
 

 
$('.' + value) 
 
    .mouseover(function(event) { 
 
    event.stopPropagation(); 
 
\t $(this).css('-webkit-box-shadow', 'inset 0px 0px 0px 4px rgba(255,248,41,1)'); 
 
\t $(this).css('-moz-box-shadow', 'inset 0px 0px 0px 4px rgba(255,248,41,1)'); 
 
\t $(this).css('box-shadow', 'inset 0px 0px 0px 4px rgba(255,248,41,1)'); 
 
\t $(this).css('cursor','pointer'); 
 
    }) 
 
    .mouseout(function() { 
 
\t $(this).css('-webkit-box-shadow', ''); 
 
\t $(this).css('-moz-box-shadow', ''); 
 
\t $(this).css('box-shadow', ''); 
 
\t $(this).css('cursor','default'); 
 
    }); 
 
    
 
    });
.wrapper 
 
{ 
 
    width:300px; 
 
    height:300px; 
 
    background:#888; 
 
    padding:50px; 
 
} 
 
.test 
 
{ 
 
    background:#fff; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="wrapper"> 
 
<div class="test"> 
 
test 
 
</div> 
 
</div>

+0

謝謝!非常容易)) – Sauron

+0

'.stopPropagation'不是一個jQuery函數,它是javascript函數。對? –

+0

@ibrahimmahrir也許,這裏是一個鏈接https://api.jquery.com/event.stoppropagation/ – Banzay