2014-08-31 52 views
-1

我是jquery的新手。我使用這段代碼來改變懸停的當前圖像或用jquery點擊另一個圖像。但它無法工作!更改事件懸停上的當前圖像或點擊jquery

<head> 
<title> Visite </title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<script type="text/javascript" src="jquery-2.1.1.min.js"> </script> 
<script> 
$('img').hover(function() { 
    $(this).attr('src', 'o.184684.jpg'); 
}) 
</script> 
</head> 

<body> 
<img src="logo11w.png" alt="photo" /> 
</body> 
</html> 

我給從http://jsfiddle.net/afzaal_ahmad_zeeshan/8H4MC/

回答

0

此例嘗試準備

$(document).ready(function() { 
    $('img').hover(function() { 
     $(this).attr('src', 'o.184684.jpg'); 
    }); 
}); 

或可替代

$(function() { 
    $('img').hover(function() { 
     $(this).attr('src', 'o.184684.jpg'); 
    }); 
}); 

這隻會在給你的鼠標在文檔中包裹的jQuery代碼。您可能還需要傳遞鼠標輸出功能:hover

$(function() { 
    $('img').hover(function() { 
     $(this).attr('src', 'o.184684.jpg'); 
    }, function() { 
     //mouse out function 
    }); 
}); 
+0

thx jwatts.it work! – BestHumain 2014-08-31 01:35:24