雖然有不同的方法來解決這個問題,可能是最簡單的將是懸停事件添加到所有的元素:
HTML
<div id="a" class="hover"></div>
<div id="b" class="hover"></div>
<div id="c" class="hover"></div>
<div id="d" class="hover"></div>
<div id="state">unhovered</div>
CSS
#a {
width: 350px;
height: 300px;
border: 1px solid #000;
background-color: #ccc;
}
#b {
position: absolute;
top: 35px;
left: 35px;
width: 35px;
height: 30px;
border: 1px solid #000;
background-color: #cca;
}
#c {
position: absolute;
top: 85px;
left: 85px;
width: 35px;
height: 30px;
border: 1px solid #000;
background-color: #cca;
}
#d {
position: absolute;
top: 85px;
left: 135px;
width: 35px;
height: 30px;
border: 1px solid #000;
background-color: #cca;
}
jQuery
$(document).ready(function(){
$('.hover').hover(
function(){
$('#state').text('hovered');
},
function(){
$('#state').text('unhovered');
}
);
});
這裏舉例:http://jsfiddle.net/userdude/H5TAG/
這是證明你的問題? http://jsfiddle.net/userdude/BqZ3R/ – 2011-03-06 20:51:38