我是新來的JQuery,我想弄清楚如何讓我的.mouseenter()和.mouseleave()方法工作。到目前爲止,我已經嘗試過使用IE8和FF,但由於一些奇怪的原因,我無法讓我的元素除了保持靜態以外的任何其他功能。下面是我到目前爲止的代碼:如何獲取JQuery代碼在我的瀏覽器上運行?
HTML:
<!Doctype html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script type="text/javascript" src="file:///D:/Documents%20and%20Settings/stsc/My%20Documents/_prac/script.js"></script>
<title>Practice</title>
</head>
<body>
<div id="red"></div>
<div id="yellow"></div>
<div id="green"></div>
</body>
</html>
CSS:
div{
height:100px;
width: 100px;
border-radius: 50px;
}
#red{
background-color: red;
}
#yellow{
background-color: yellow;
}
#green{
background-color: green;
}
JS:
$(document).ready(function(){
$('div').mouseenter(function(){
$(this).animate({
width: '+=10px'
});
});
$('div').mouseleave(function(){
$(this).animate({
width: '-=10px'
});
});
$('div').click(function() {
$(this).toggle(1000);
});
});
這只是一個簡單的例子使用jQuery練習。預先感謝幫助傢伙!
按下「F12」,當您在瀏覽器的時候,你會看到被帶到了一個控制檯,錯誤最可能的狀態,'」無法加載資源:資源未找到'',並且發生了'500服務器錯誤'。 – Ohgodwhy 2013-04-24 23:11:15
那麼,你需要包含jQuery(在你的例子中你不需要)。 – Niko 2013-04-24 23:12:56
我複製並將上面的代碼粘貼到[jsFiddle](http://jsfiddle.net/XNAKj/) – 2013-04-24 23:14:22