1.下面是簡單的jq hover
$('td').hover(function() {
// 鼠標移入時添加hover類
// code
}, function() {
// 鼠標移出時移出hover類
//code
});
2.嵌套hover不能寫在一起,要分開
$('td').hover(function() {
// 鼠標移入時添加hover類
var index = $(this).data('id');
hoverItem(index)
}, function() {
// 鼠標移出時移出hover類
});
function hoverItem(index){
$('#started'+index).hover(function() {
// 鼠標移入時添加hover類
$('#started'+index).removeClass('btn-gray')
$('#started'+index).addClass('btn-red')
$('#started'+index).text('停止')
}, function() {
// 鼠標移出時移出hover類
$('#started'+index).removeClass('btn-red')
$('#started'+index).addClass('btn-gray')
$('#started'+index).text('已啓動')
});
}
效果如下圖