我无法理解为什么只有第一个函数($(“#ContentWel”))才有效。
但如果我把第二个函数(“#ContentCan”)放在首位,它只能起作用:
$(document).ready(function(){
$("#ContentWel").hover(function(){
$('#counterimage').attr('src', 'img/01.png');
});
$("#ContentCan").hover(function(){
$('#counterimage').attr('src', 'img/02.png');
});
$("#ContentCli").hover(function(){
$('#counterimage').attr('src', 'img/03.png');
});
$("#ContentTesti").hover(function(){
$('#counterimage').attr('src', 'img/04.png');
});
$("#ContentCont").hover(function(){
$('#counterimage').attr('src', 'img/05.png');
});
$("#ContentPri").hover(function(){
$('#counterimage').attr('src', 'img/06.png');
});
});
谢谢,Guilherme
答案 0 :(得分:4)
.hover()
需要一个mouseenter和mouseleave函数
$("#ContentWel").hover(function(){
$('#counterimage').attr('src', 'img/01.png');
}, function(){
// something else happens
});
或者您只是使用mouseenter:
$("#ContentWel").mouseenter(function(){
$('#counterimage').attr('src', 'img/01.png');
});
答案 1 :(得分:0)
为了更好地了解您的功能,请添加try / catches
try {
$("#ContentWel").hover(function(){
$('#counterimage').attr('src', 'img/01.png');
});
} catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
try {
$("#ContentCan").hover(function(){
$('#counterimage').attr('src', 'img/02.png');
});
} catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
try {
$("#ContentCli").hover(function(){
$('#counterimage').attr('src', 'img/03.png');
});
} catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
try {
$("#ContentTesti").hover(function(){
$('#counterimage').attr('src', 'img/04.png');
});
} catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
try {
$("#ContentCont").hover(function(){
$('#counterimage').attr('src', 'img/05.png');
});
} catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }
try {
$("#ContentPri").hover(function(){
$('#counterimage').attr('src', 'img/06.png');
});
} catch (e) { if (window.console !== undefined && window.console.log !== undefined) { window.console.log(e.message); } else { alert(e.message); } }